@nextsparkjs/core 0.1.0-beta.82 → 0.1.0-beta.84
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.
- package/dist/components/entities/wrappers/EntityDetailWrapper.d.ts.map +1 -1
- package/dist/components/entities/wrappers/EntityDetailWrapper.js +11 -39
- package/dist/hooks/useEntityQuery.d.ts.map +1 -1
- package/dist/hooks/useEntityQuery.js +21 -3
- package/dist/lib/theme/get-default-theme-mode.d.ts +11 -0
- package/dist/lib/theme/get-default-theme-mode.d.ts.map +1 -1
- package/dist/lib/theme/get-default-theme-mode.js +42 -25
- package/dist/styles/classes.json +1 -1
- package/dist/types/theme.d.ts +2 -0
- package/dist/types/theme.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/templates/app/(auth)/forgot-password/page.tsx +0 -216
- package/dist/templates/app/(auth)/layout.tsx +0 -51
- package/dist/templates/app/(auth)/login/page.tsx +0 -21
- package/dist/templates/app/(auth)/reset-password/page.tsx +0 -212
- package/dist/templates/app/(auth)/signup/page.tsx +0 -21
- package/dist/templates/app/(auth)/verify-email/page.tsx +0 -190
- package/dist/templates/app/(public)/[...slug]/page.tsx +0 -378
- package/dist/templates/app/(public)/docs/[section]/[page]/page.tsx +0 -90
- package/dist/templates/app/(public)/docs/layout.tsx +0 -25
- package/dist/templates/app/(public)/docs/page.tsx +0 -81
- package/dist/templates/app/(public)/layout.tsx +0 -41
- package/dist/templates/app/(public)/page.tsx +0 -19
- package/dist/templates/app/403/page.tsx +0 -89
- package/dist/templates/app/api/auth/[...all]/route.ts +0 -78
- package/dist/templates/app/api/cron/billing/lifecycle/route.ts +0 -98
- package/dist/templates/app/api/csp-report/route.ts +0 -175
- package/dist/templates/app/api/devtools/config/entities/route.ts +0 -108
- package/dist/templates/app/api/devtools/config/theme/route.ts +0 -66
- package/dist/templates/app/api/devtools/tests/[...path]/route.ts +0 -130
- package/dist/templates/app/api/devtools/tests/route.ts +0 -134
- package/dist/templates/app/api/health/route.ts +0 -29
- package/dist/templates/app/api/internal/user-metadata/route.ts +0 -36
- package/dist/templates/app/api/superadmin/subscriptions/route.ts +0 -310
- package/dist/templates/app/api/superadmin/teams/[teamId]/route.ts +0 -286
- package/dist/templates/app/api/superadmin/teams/route.ts +0 -188
- package/dist/templates/app/api/superadmin/users/[userId]/route.ts +0 -540
- package/dist/templates/app/api/superadmin/users/route.ts +0 -323
- package/dist/templates/app/api/user/delete-account/route.ts +0 -55
- package/dist/templates/app/api/user/plan-flags/route.ts +0 -283
- package/dist/templates/app/api/user/profile/route.ts +0 -133
- package/dist/templates/app/api/v1/[entity]/[id]/child/[childType]/[childId]/route.ts +0 -210
- package/dist/templates/app/api/v1/[entity]/[id]/child/[childType]/route.ts +0 -331
- package/dist/templates/app/api/v1/[entity]/[id]/route.ts +0 -35
- package/dist/templates/app/api/v1/[entity]/docs.md +0 -369
- package/dist/templates/app/api/v1/[entity]/presets.ts +0 -194
- package/dist/templates/app/api/v1/[entity]/route.ts +0 -31
- package/dist/templates/app/api/v1/api-keys/[id]/route.ts +0 -303
- package/dist/templates/app/api/v1/api-keys/docs.md +0 -101
- package/dist/templates/app/api/v1/api-keys/presets.ts +0 -31
- package/dist/templates/app/api/v1/api-keys/route.ts +0 -250
- package/dist/templates/app/api/v1/auth/docs.md +0 -184
- package/dist/templates/app/api/v1/auth/presets.ts +0 -44
- package/dist/templates/app/api/v1/auth/signup-with-invite/route.ts +0 -227
- package/dist/templates/app/api/v1/billing/cancel/route.ts +0 -206
- package/dist/templates/app/api/v1/billing/change-plan/route.ts +0 -97
- package/dist/templates/app/api/v1/billing/check-action/route.ts +0 -81
- package/dist/templates/app/api/v1/billing/checkout/route.ts +0 -124
- package/dist/templates/app/api/v1/billing/docs.md +0 -209
- package/dist/templates/app/api/v1/billing/plans/route.ts +0 -85
- package/dist/templates/app/api/v1/billing/portal/route.ts +0 -90
- package/dist/templates/app/api/v1/billing/presets.ts +0 -121
- package/dist/templates/app/api/v1/billing/webhooks/stripe/route.ts +0 -428
- package/dist/templates/app/api/v1/blocks/[slug]/route.ts +0 -29
- package/dist/templates/app/api/v1/blocks/docs.md +0 -173
- package/dist/templates/app/api/v1/blocks/presets.ts +0 -121
- package/dist/templates/app/api/v1/blocks/route.ts +0 -45
- package/dist/templates/app/api/v1/blocks/validate/route.ts +0 -45
- package/dist/templates/app/api/v1/cron/docs.md +0 -116
- package/dist/templates/app/api/v1/cron/presets.ts +0 -26
- package/dist/templates/app/api/v1/cron/process/route.ts +0 -108
- package/dist/templates/app/api/v1/devtools/blocks/route.ts +0 -82
- package/dist/templates/app/api/v1/devtools/docs/route.ts +0 -150
- package/dist/templates/app/api/v1/devtools/docs.md +0 -204
- package/dist/templates/app/api/v1/devtools/features/route.ts +0 -61
- package/dist/templates/app/api/v1/devtools/flows/route.ts +0 -61
- package/dist/templates/app/api/v1/devtools/presets.ts +0 -113
- package/dist/templates/app/api/v1/devtools/scheduled-actions/route.ts +0 -120
- package/dist/templates/app/api/v1/devtools/testing/route.ts +0 -82
- package/dist/templates/app/api/v1/media/docs.md +0 -117
- package/dist/templates/app/api/v1/media/presets.ts +0 -24
- package/dist/templates/app/api/v1/media/upload/route.ts +0 -150
- package/dist/templates/app/api/v1/patterns/[id]/usages/route.ts +0 -116
- package/dist/templates/app/api/v1/plugin/[...path]/route.ts +0 -373
- package/dist/templates/app/api/v1/plugin/docs.md +0 -79
- package/dist/templates/app/api/v1/plugin/presets.ts +0 -21
- package/dist/templates/app/api/v1/plugin/route.ts +0 -96
- package/dist/templates/app/api/v1/post-categories/[id]/route.ts +0 -255
- package/dist/templates/app/api/v1/post-categories/docs.md +0 -134
- package/dist/templates/app/api/v1/post-categories/presets.ts +0 -78
- package/dist/templates/app/api/v1/post-categories/route.ts +0 -119
- package/dist/templates/app/api/v1/team-invitations/[token]/accept/route.ts +0 -179
- package/dist/templates/app/api/v1/team-invitations/[token]/decline/route.ts +0 -120
- package/dist/templates/app/api/v1/team-invitations/[token]/route.ts +0 -89
- package/dist/templates/app/api/v1/team-invitations/docs.md +0 -88
- package/dist/templates/app/api/v1/team-invitations/presets.ts +0 -43
- package/dist/templates/app/api/v1/team-invitations/route.ts +0 -114
- package/dist/templates/app/api/v1/teams/[teamId]/invitations/route.ts +0 -171
- package/dist/templates/app/api/v1/teams/[teamId]/invoices/[invoiceNumber]/route.ts +0 -105
- package/dist/templates/app/api/v1/teams/[teamId]/invoices/route.ts +0 -125
- package/dist/templates/app/api/v1/teams/[teamId]/members/[memberId]/route.ts +0 -263
- package/dist/templates/app/api/v1/teams/[teamId]/members/route.ts +0 -358
- package/dist/templates/app/api/v1/teams/[teamId]/route.ts +0 -322
- package/dist/templates/app/api/v1/teams/[teamId]/subscription/route.ts +0 -50
- package/dist/templates/app/api/v1/teams/[teamId]/usage/[limitSlug]/route.ts +0 -91
- package/dist/templates/app/api/v1/teams/docs.md +0 -320
- package/dist/templates/app/api/v1/teams/presets.ts +0 -178
- package/dist/templates/app/api/v1/teams/route.ts +0 -293
- package/dist/templates/app/api/v1/teams/switch/route.ts +0 -88
- package/dist/templates/app/api/v1/theme/[...path]/route.ts +0 -361
- package/dist/templates/app/api/v1/theme/docs.md +0 -74
- package/dist/templates/app/api/v1/theme/presets.ts +0 -21
- package/dist/templates/app/api/v1/theme/route.ts +0 -96
- package/dist/templates/app/api/v1/users/[id]/meta/[key]/route.ts +0 -363
- package/dist/templates/app/api/v1/users/[id]/route.ts +0 -302
- package/dist/templates/app/api/v1/users/docs.md +0 -93
- package/dist/templates/app/api/v1/users/presets.ts +0 -59
- package/dist/templates/app/api/v1/users/route.ts +0 -197
- package/dist/templates/app/dashboard/(main)/[entity]/[id]/edit/page.tsx +0 -117
- package/dist/templates/app/dashboard/(main)/[entity]/[id]/page.tsx +0 -103
- package/dist/templates/app/dashboard/(main)/[entity]/create/page.tsx +0 -95
- package/dist/templates/app/dashboard/(main)/[entity]/error.tsx +0 -51
- package/dist/templates/app/dashboard/(main)/[entity]/layout.tsx +0 -113
- package/dist/templates/app/dashboard/(main)/[entity]/loading.tsx +0 -61
- package/dist/templates/app/dashboard/(main)/[entity]/page.tsx +0 -90
- package/dist/templates/app/dashboard/(main)/layout.tsx +0 -98
- package/dist/templates/app/dashboard/(main)/loading.tsx +0 -5
- package/dist/templates/app/dashboard/(main)/page.tsx +0 -201
- package/dist/templates/app/dashboard/(main)/patterns/[id]/edit/page.tsx +0 -114
- package/dist/templates/app/dashboard/(main)/patterns/[id]/page.tsx +0 -20
- package/dist/templates/app/dashboard/(main)/patterns/[id]/reports/page.tsx +0 -171
- package/dist/templates/app/dashboard/(main)/patterns/create/page.tsx +0 -86
- package/dist/templates/app/dashboard/(main)/patterns/page.tsx +0 -444
- package/dist/templates/app/dashboard/features/analytics/page.tsx +0 -35
- package/dist/templates/app/dashboard/features/automation/page.tsx +0 -35
- package/dist/templates/app/dashboard/features/layout.tsx +0 -13
- package/dist/templates/app/dashboard/features/loading.tsx +0 -5
- package/dist/templates/app/dashboard/features/webhooks/page.tsx +0 -35
- package/dist/templates/app/dashboard/layout.tsx +0 -86
- package/dist/templates/app/dashboard/permission-denied/page.tsx +0 -29
- package/dist/templates/app/dashboard/settings/api-keys/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/api-keys/page.tsx +0 -513
- package/dist/templates/app/dashboard/settings/billing/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/billing/page.tsx +0 -284
- package/dist/templates/app/dashboard/settings/invoices/[invoiceNumber]/page.tsx +0 -222
- package/dist/templates/app/dashboard/settings/invoices/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/invoices/page.tsx +0 -82
- package/dist/templates/app/dashboard/settings/layout.tsx +0 -151
- package/dist/templates/app/dashboard/settings/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/notifications/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/notifications/page.tsx +0 -462
- package/dist/templates/app/dashboard/settings/page.tsx +0 -92
- package/dist/templates/app/dashboard/settings/password/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/password/page.tsx +0 -306
- package/dist/templates/app/dashboard/settings/plans/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/plans/page.tsx +0 -40
- package/dist/templates/app/dashboard/settings/profile/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/profile/page.tsx +0 -686
- package/dist/templates/app/dashboard/settings/security/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/security/page.tsx +0 -505
- package/dist/templates/app/dashboard/settings/teams/loading.tsx +0 -5
- package/dist/templates/app/dashboard/settings/teams/page.tsx +0 -272
- package/dist/templates/app/dashboard/settings/teams/permissions/page.tsx +0 -92
- package/dist/templates/app/devtools/blocks/[slug]/page.tsx +0 -39
- package/dist/templates/app/devtools/blocks/page.tsx +0 -31
- package/dist/templates/app/devtools/config/page.tsx +0 -31
- package/dist/templates/app/devtools/features/page.tsx +0 -31
- package/dist/templates/app/devtools/flows/page.tsx +0 -31
- package/dist/templates/app/devtools/layout.tsx +0 -58
- package/dist/templates/app/devtools/page.tsx +0 -121
- package/dist/templates/app/devtools/scheduled-actions/page.tsx +0 -157
- package/dist/templates/app/devtools/style/page.tsx +0 -330
- package/dist/templates/app/devtools/tags/page.tsx +0 -31
- package/dist/templates/app/devtools/tests/[[...path]]/page.tsx +0 -47
- package/dist/templates/app/favicon.ico +0 -0
- package/dist/templates/app/globals.css +0 -12
- package/dist/templates/app/layout.tsx +0 -96
- package/dist/templates/app/public/page.tsx +0 -30
- package/dist/templates/app/superadmin/docs/[section]/[page]/page.tsx +0 -92
- package/dist/templates/app/superadmin/docs/page.tsx +0 -75
- package/dist/templates/app/superadmin/layout.tsx +0 -67
- package/dist/templates/app/superadmin/page.tsx +0 -149
- package/dist/templates/app/superadmin/subscriptions/page.tsx +0 -655
- package/dist/templates/app/superadmin/team-roles/page.tsx +0 -493
- package/dist/templates/app/superadmin/teams/[teamId]/page.tsx +0 -687
- package/dist/templates/app/superadmin/teams/page.tsx +0 -302
- package/dist/templates/app/superadmin/users/[userId]/page.tsx +0 -548
- package/dist/templates/app/superadmin/users/page.tsx +0 -528
- package/templates/app/(auth)/forgot-password/page.tsx +0 -216
- package/templates/app/(auth)/layout.tsx +0 -51
- package/templates/app/(auth)/login/page.tsx +0 -21
- package/templates/app/(auth)/reset-password/page.tsx +0 -212
- package/templates/app/(auth)/signup/page.tsx +0 -21
- package/templates/app/(auth)/verify-email/page.tsx +0 -190
- package/templates/app/(public)/[...slug]/page.tsx +0 -378
- package/templates/app/(public)/docs/[section]/[page]/page.tsx +0 -90
- package/templates/app/(public)/docs/layout.tsx +0 -25
- package/templates/app/(public)/docs/page.tsx +0 -81
- package/templates/app/(public)/layout.tsx +0 -41
- package/templates/app/(public)/page.tsx +0 -19
- package/templates/app/403/page.tsx +0 -89
- package/templates/app/api/auth/[...all]/route.ts +0 -78
- package/templates/app/api/cron/billing/lifecycle/route.ts +0 -98
- package/templates/app/api/csp-report/route.ts +0 -175
- package/templates/app/api/devtools/config/entities/route.ts +0 -108
- package/templates/app/api/devtools/config/theme/route.ts +0 -66
- package/templates/app/api/devtools/tests/[...path]/route.ts +0 -130
- package/templates/app/api/devtools/tests/route.ts +0 -134
- package/templates/app/api/health/route.ts +0 -29
- package/templates/app/api/internal/user-metadata/route.ts +0 -36
- package/templates/app/api/superadmin/subscriptions/route.ts +0 -310
- package/templates/app/api/superadmin/teams/[teamId]/route.ts +0 -286
- package/templates/app/api/superadmin/teams/route.ts +0 -188
- package/templates/app/api/superadmin/users/[userId]/route.ts +0 -540
- package/templates/app/api/superadmin/users/route.ts +0 -323
- package/templates/app/api/user/delete-account/route.ts +0 -55
- package/templates/app/api/user/plan-flags/route.ts +0 -283
- package/templates/app/api/user/profile/route.ts +0 -133
- package/templates/app/api/v1/[entity]/[id]/child/[childType]/[childId]/route.ts +0 -210
- package/templates/app/api/v1/[entity]/[id]/child/[childType]/route.ts +0 -331
- package/templates/app/api/v1/[entity]/[id]/route.ts +0 -35
- package/templates/app/api/v1/[entity]/docs.md +0 -369
- package/templates/app/api/v1/[entity]/presets.ts +0 -194
- package/templates/app/api/v1/[entity]/route.ts +0 -31
- package/templates/app/api/v1/api-keys/[id]/route.ts +0 -303
- package/templates/app/api/v1/api-keys/docs.md +0 -101
- package/templates/app/api/v1/api-keys/presets.ts +0 -31
- package/templates/app/api/v1/api-keys/route.ts +0 -250
- package/templates/app/api/v1/auth/docs.md +0 -184
- package/templates/app/api/v1/auth/presets.ts +0 -44
- package/templates/app/api/v1/auth/signup-with-invite/route.ts +0 -227
- package/templates/app/api/v1/billing/cancel/route.ts +0 -206
- package/templates/app/api/v1/billing/change-plan/route.ts +0 -97
- package/templates/app/api/v1/billing/check-action/route.ts +0 -81
- package/templates/app/api/v1/billing/checkout/route.ts +0 -124
- package/templates/app/api/v1/billing/docs.md +0 -209
- package/templates/app/api/v1/billing/plans/route.ts +0 -85
- package/templates/app/api/v1/billing/portal/route.ts +0 -90
- package/templates/app/api/v1/billing/presets.ts +0 -121
- package/templates/app/api/v1/billing/webhooks/stripe/route.ts +0 -428
- package/templates/app/api/v1/blocks/[slug]/route.ts +0 -29
- package/templates/app/api/v1/blocks/docs.md +0 -173
- package/templates/app/api/v1/blocks/presets.ts +0 -121
- package/templates/app/api/v1/blocks/route.ts +0 -45
- package/templates/app/api/v1/blocks/validate/route.ts +0 -45
- package/templates/app/api/v1/cron/docs.md +0 -116
- package/templates/app/api/v1/cron/presets.ts +0 -26
- package/templates/app/api/v1/cron/process/route.ts +0 -108
- package/templates/app/api/v1/devtools/blocks/route.ts +0 -82
- package/templates/app/api/v1/devtools/docs/route.ts +0 -150
- package/templates/app/api/v1/devtools/docs.md +0 -204
- package/templates/app/api/v1/devtools/features/route.ts +0 -61
- package/templates/app/api/v1/devtools/flows/route.ts +0 -61
- package/templates/app/api/v1/devtools/presets.ts +0 -113
- package/templates/app/api/v1/devtools/scheduled-actions/route.ts +0 -120
- package/templates/app/api/v1/devtools/testing/route.ts +0 -82
- package/templates/app/api/v1/media/docs.md +0 -117
- package/templates/app/api/v1/media/presets.ts +0 -24
- package/templates/app/api/v1/media/upload/route.ts +0 -150
- package/templates/app/api/v1/patterns/[id]/usages/route.ts +0 -116
- package/templates/app/api/v1/plugin/[...path]/route.ts +0 -373
- package/templates/app/api/v1/plugin/docs.md +0 -79
- package/templates/app/api/v1/plugin/presets.ts +0 -21
- package/templates/app/api/v1/plugin/route.ts +0 -96
- package/templates/app/api/v1/post-categories/[id]/route.ts +0 -255
- package/templates/app/api/v1/post-categories/docs.md +0 -134
- package/templates/app/api/v1/post-categories/presets.ts +0 -78
- package/templates/app/api/v1/post-categories/route.ts +0 -119
- package/templates/app/api/v1/team-invitations/[token]/accept/route.ts +0 -179
- package/templates/app/api/v1/team-invitations/[token]/decline/route.ts +0 -120
- package/templates/app/api/v1/team-invitations/[token]/route.ts +0 -89
- package/templates/app/api/v1/team-invitations/docs.md +0 -88
- package/templates/app/api/v1/team-invitations/presets.ts +0 -43
- package/templates/app/api/v1/team-invitations/route.ts +0 -114
- package/templates/app/api/v1/teams/[teamId]/invitations/route.ts +0 -171
- package/templates/app/api/v1/teams/[teamId]/invoices/[invoiceNumber]/route.ts +0 -105
- package/templates/app/api/v1/teams/[teamId]/invoices/route.ts +0 -125
- package/templates/app/api/v1/teams/[teamId]/members/[memberId]/route.ts +0 -263
- package/templates/app/api/v1/teams/[teamId]/members/route.ts +0 -358
- package/templates/app/api/v1/teams/[teamId]/route.ts +0 -322
- package/templates/app/api/v1/teams/[teamId]/subscription/route.ts +0 -50
- package/templates/app/api/v1/teams/[teamId]/usage/[limitSlug]/route.ts +0 -91
- package/templates/app/api/v1/teams/docs.md +0 -320
- package/templates/app/api/v1/teams/presets.ts +0 -178
- package/templates/app/api/v1/teams/route.ts +0 -293
- package/templates/app/api/v1/teams/switch/route.ts +0 -88
- package/templates/app/api/v1/theme/[...path]/route.ts +0 -361
- package/templates/app/api/v1/theme/docs.md +0 -74
- package/templates/app/api/v1/theme/presets.ts +0 -21
- package/templates/app/api/v1/theme/route.ts +0 -96
- package/templates/app/api/v1/users/[id]/meta/[key]/route.ts +0 -363
- package/templates/app/api/v1/users/[id]/route.ts +0 -302
- package/templates/app/api/v1/users/docs.md +0 -93
- package/templates/app/api/v1/users/presets.ts +0 -59
- package/templates/app/api/v1/users/route.ts +0 -197
- package/templates/app/dashboard/(main)/[entity]/[id]/edit/page.tsx +0 -117
- package/templates/app/dashboard/(main)/[entity]/[id]/page.tsx +0 -103
- package/templates/app/dashboard/(main)/[entity]/create/page.tsx +0 -95
- package/templates/app/dashboard/(main)/[entity]/error.tsx +0 -51
- package/templates/app/dashboard/(main)/[entity]/layout.tsx +0 -113
- package/templates/app/dashboard/(main)/[entity]/loading.tsx +0 -61
- package/templates/app/dashboard/(main)/[entity]/page.tsx +0 -90
- package/templates/app/dashboard/(main)/layout.tsx +0 -98
- package/templates/app/dashboard/(main)/loading.tsx +0 -5
- package/templates/app/dashboard/(main)/page.tsx +0 -201
- package/templates/app/dashboard/(main)/patterns/[id]/edit/page.tsx +0 -114
- package/templates/app/dashboard/(main)/patterns/[id]/page.tsx +0 -20
- package/templates/app/dashboard/(main)/patterns/[id]/reports/page.tsx +0 -171
- package/templates/app/dashboard/(main)/patterns/create/page.tsx +0 -86
- package/templates/app/dashboard/(main)/patterns/page.tsx +0 -444
- package/templates/app/dashboard/features/analytics/page.tsx +0 -35
- package/templates/app/dashboard/features/automation/page.tsx +0 -35
- package/templates/app/dashboard/features/layout.tsx +0 -13
- package/templates/app/dashboard/features/loading.tsx +0 -5
- package/templates/app/dashboard/features/webhooks/page.tsx +0 -35
- package/templates/app/dashboard/layout.tsx +0 -86
- package/templates/app/dashboard/permission-denied/page.tsx +0 -29
- package/templates/app/dashboard/settings/api-keys/loading.tsx +0 -5
- package/templates/app/dashboard/settings/api-keys/page.tsx +0 -513
- package/templates/app/dashboard/settings/billing/loading.tsx +0 -5
- package/templates/app/dashboard/settings/billing/page.tsx +0 -284
- package/templates/app/dashboard/settings/invoices/[invoiceNumber]/page.tsx +0 -222
- package/templates/app/dashboard/settings/invoices/loading.tsx +0 -5
- package/templates/app/dashboard/settings/invoices/page.tsx +0 -82
- package/templates/app/dashboard/settings/layout.tsx +0 -151
- package/templates/app/dashboard/settings/loading.tsx +0 -5
- package/templates/app/dashboard/settings/notifications/loading.tsx +0 -5
- package/templates/app/dashboard/settings/notifications/page.tsx +0 -462
- package/templates/app/dashboard/settings/page.tsx +0 -92
- package/templates/app/dashboard/settings/password/loading.tsx +0 -5
- package/templates/app/dashboard/settings/password/page.tsx +0 -306
- package/templates/app/dashboard/settings/plans/loading.tsx +0 -5
- package/templates/app/dashboard/settings/plans/page.tsx +0 -40
- package/templates/app/dashboard/settings/profile/loading.tsx +0 -5
- package/templates/app/dashboard/settings/profile/page.tsx +0 -686
- package/templates/app/dashboard/settings/security/loading.tsx +0 -5
- package/templates/app/dashboard/settings/security/page.tsx +0 -505
- package/templates/app/dashboard/settings/teams/loading.tsx +0 -5
- package/templates/app/dashboard/settings/teams/page.tsx +0 -272
- package/templates/app/dashboard/settings/teams/permissions/page.tsx +0 -92
- package/templates/app/devtools/blocks/[slug]/page.tsx +0 -39
- package/templates/app/devtools/blocks/page.tsx +0 -31
- package/templates/app/devtools/config/page.tsx +0 -31
- package/templates/app/devtools/features/page.tsx +0 -31
- package/templates/app/devtools/flows/page.tsx +0 -31
- package/templates/app/devtools/layout.tsx +0 -58
- package/templates/app/devtools/page.tsx +0 -121
- package/templates/app/devtools/scheduled-actions/page.tsx +0 -157
- package/templates/app/devtools/style/page.tsx +0 -330
- package/templates/app/devtools/tags/page.tsx +0 -31
- package/templates/app/devtools/tests/[[...path]]/page.tsx +0 -47
- package/templates/app/favicon.ico +0 -0
- package/templates/app/globals.css +0 -12
- package/templates/app/layout.tsx +0 -96
- package/templates/app/public/page.tsx +0 -30
- package/templates/app/superadmin/docs/[section]/[page]/page.tsx +0 -92
- package/templates/app/superadmin/docs/page.tsx +0 -75
- package/templates/app/superadmin/layout.tsx +0 -67
- package/templates/app/superadmin/page.tsx +0 -149
- package/templates/app/superadmin/subscriptions/page.tsx +0 -655
- package/templates/app/superadmin/team-roles/page.tsx +0 -493
- package/templates/app/superadmin/teams/[teamId]/page.tsx +0 -687
- package/templates/app/superadmin/teams/page.tsx +0 -302
- package/templates/app/superadmin/users/[userId]/page.tsx +0 -548
- 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
|
-
}
|