@nextsparkjs/core 0.1.0-beta.184 → 0.1.0-beta.186
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/app/guards/DeveloperGuard.d.ts.map +1 -1
- package/dist/components/app/guards/SuperAdminGuard.d.ts.map +1 -1
- package/dist/components/app/layouts/PublicFooter.d.ts.map +1 -1
- package/dist/components/app/layouts/PublicFooter.js +2 -2
- package/dist/components/app/layouts/PublicNavbar.d.ts.map +1 -1
- package/dist/components/app/layouts/PublicNavbar.js +2 -2
- package/dist/components/app/misc/ThemeToggle.d.ts.map +1 -1
- package/dist/components/app/misc/ThemeToggle.js +4 -1
- package/dist/components/auth/DevKeyring.d.ts.map +1 -1
- package/dist/components/auth/DevKeyring.js +10 -2
- package/dist/components/auth/SessionCookieRefresher.d.ts +21 -0
- package/dist/components/auth/SessionCookieRefresher.d.ts.map +1 -0
- package/dist/components/auth/SessionCookieRefresher.js +11 -0
- package/dist/components/auth/forms/LoginForm.d.ts.map +1 -1
- package/dist/components/auth/forms/LoginForm.js +300 -6
- package/dist/components/auth/index.d.ts +1 -0
- package/dist/components/auth/index.d.ts.map +1 -1
- package/dist/components/auth/index.js +2 -0
- package/dist/components/billing/InvoicesTable.d.ts.map +1 -1
- package/dist/components/billing/InvoicesTable.js +4 -3
- package/dist/components/dashboard/block-editor/dynamic-form.d.ts.map +1 -1
- package/dist/components/dashboard/layouts/AuthGuard.d.ts.map +1 -1
- package/dist/components/dashboard/layouts/AuthGuard.js +2 -2
- package/dist/components/dashboard/layouts/DashboardAuthLayout.d.ts.map +1 -1
- package/dist/components/dashboard/layouts/DashboardAuthLayout.js +2 -2
- package/dist/components/dashboard/layouts/DashboardAuthSkeleton.d.ts +17 -0
- package/dist/components/dashboard/layouts/DashboardAuthSkeleton.d.ts.map +1 -0
- package/dist/components/dashboard/layouts/DashboardAuthSkeleton.js +52 -0
- package/dist/components/dashboard/layouts/Sidebar.d.ts.map +1 -1
- package/dist/components/dashboard/layouts/Sidebar.js +2 -3
- package/dist/components/dashboard/layouts/TopNavbar.js +2 -2
- package/dist/components/dashboard/layouts/index.d.ts +1 -0
- package/dist/components/dashboard/layouts/index.d.ts.map +1 -1
- package/dist/components/dashboard/layouts/index.js +2 -0
- package/dist/components/entities/EntityFieldRenderer.d.ts.map +1 -1
- package/dist/components/entities/EntityFieldRenderer.js +3 -0
- package/dist/components/entities/EntityTable.d.ts.map +1 -1
- package/dist/components/entities/EntityTable.js +2 -1
- package/dist/components/entities/wrappers/EntityFormWrapper.d.ts.map +1 -1
- package/dist/components/entities/wrappers/EntityFormWrapper.js +7 -2
- package/dist/components/ui/combobox.d.ts +8 -1
- package/dist/components/ui/combobox.d.ts.map +1 -1
- package/dist/components/ui/combobox.js +37 -44
- package/dist/components/ui/country-select.d.ts +3 -1
- package/dist/components/ui/country-select.d.ts.map +1 -1
- package/dist/components/ui/country-select.js +3 -1
- package/dist/components/ui/currency-select.d.ts +3 -1
- package/dist/components/ui/currency-select.d.ts.map +1 -1
- package/dist/components/ui/currency-select.js +3 -1
- package/dist/components/ui/sheet.d.ts +5 -0
- package/dist/components/ui/sheet.d.ts.map +1 -1
- package/dist/components/ui/sheet.js +46 -26
- package/dist/components/ui/timezone-select.d.ts +3 -1
- package/dist/components/ui/timezone-select.d.ts.map +1 -1
- package/dist/components/ui/timezone-select.js +3 -1
- package/dist/contexts/TeamContext.d.ts +6 -0
- package/dist/contexts/TeamContext.d.ts.map +1 -1
- package/dist/contexts/TeamContext.js +8 -1
- package/dist/emails/otp-verification.d.ts.map +1 -1
- package/dist/emails/reset-password.d.ts.map +1 -1
- package/dist/emails/team-invitation.d.ts.map +1 -1
- package/dist/emails/team-invitation.js +3 -2
- package/dist/emails/verify-email.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useAuth.d.ts +103 -25
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +24 -0
- package/dist/hooks/useEnsureUserMetadata.d.ts +22 -0
- package/dist/hooks/useEnsureUserMetadata.d.ts.map +1 -1
- package/dist/hooks/useEnsureUserMetadata.js +18 -5
- package/dist/hooks/useSessionCookieRefresh.d.ts +35 -0
- package/dist/hooks/useSessionCookieRefresh.d.ts.map +1 -0
- package/dist/hooks/useSessionCookieRefresh.js +49 -0
- package/dist/hooks/useValidationSchemas.d.ts +7 -7
- package/dist/lib/api/api-error.d.ts +3 -1
- package/dist/lib/api/api-error.d.ts.map +1 -1
- package/dist/lib/api/api-error.js +4 -2
- package/dist/lib/api/auth/dual-auth.d.ts +45 -3
- package/dist/lib/api/auth/dual-auth.d.ts.map +1 -1
- package/dist/lib/api/auth/dual-auth.js +42 -7
- package/dist/lib/api/auth/permissions.d.ts +7 -2
- package/dist/lib/api/auth/permissions.d.ts.map +1 -1
- package/dist/lib/api/auth/permissions.js +2 -2
- package/dist/lib/api/auth/scope-policy.d.ts +71 -0
- package/dist/lib/api/auth/scope-policy.d.ts.map +1 -0
- package/dist/lib/api/auth/scope-policy.js +53 -0
- package/dist/lib/api/auth.d.ts +35 -3
- package/dist/lib/api/auth.d.ts.map +1 -1
- package/dist/lib/api/auth.js +54 -23
- package/dist/lib/api/entity/audit-log.d.ts +35 -0
- package/dist/lib/api/entity/audit-log.d.ts.map +1 -0
- package/dist/lib/api/entity/audit-log.js +35 -0
- package/dist/lib/api/entity/generic-handler.d.ts.map +1 -1
- package/dist/lib/api/entity/generic-handler.js +333 -155
- package/dist/lib/api/helpers.d.ts +29 -4
- package/dist/lib/api/helpers.d.ts.map +1 -1
- package/dist/lib/api/helpers.js +30 -6
- package/dist/lib/api/keys.d.ts +16 -0
- package/dist/lib/api/keys.d.ts.map +1 -1
- package/dist/lib/api/keys.js +19 -1
- package/dist/lib/api/routes/patterns-usages.d.ts.map +1 -1
- package/dist/lib/api/routes/patterns-usages.js +3 -11
- package/dist/lib/auth/auth-methods.d.ts +52 -0
- package/dist/lib/auth/auth-methods.d.ts.map +1 -0
- package/dist/lib/auth/auth-methods.js +63 -0
- package/dist/lib/auth/registration-guard-plugin.d.ts.map +1 -1
- package/dist/lib/auth/registration-helpers.d.ts +9 -0
- package/dist/lib/auth/registration-helpers.d.ts.map +1 -1
- package/dist/lib/auth/registration-helpers.js +8 -2
- package/dist/lib/auth/security-notifications/device-fingerprint.d.ts +52 -0
- package/dist/lib/auth/security-notifications/device-fingerprint.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/device-fingerprint.js +42 -0
- package/dist/lib/auth/security-notifications/dispatcher.d.ts +37 -0
- package/dist/lib/auth/security-notifications/dispatcher.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/dispatcher.js +157 -0
- package/dist/lib/auth/security-notifications/index.d.ts +20 -0
- package/dist/lib/auth/security-notifications/index.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/index.js +22 -0
- package/dist/lib/auth/security-notifications/registry.d.ts +36 -0
- package/dist/lib/auth/security-notifications/registry.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/registry.js +26 -0
- package/dist/lib/auth/security-notifications/templates/email-changed.d.ts +12 -0
- package/dist/lib/auth/security-notifications/templates/email-changed.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/templates/email-changed.js +43 -0
- package/dist/lib/auth/security-notifications/templates/new-device-login.d.ts +7 -0
- package/dist/lib/auth/security-notifications/templates/new-device-login.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/templates/new-device-login.js +46 -0
- package/dist/lib/auth/security-notifications/templates/password-changed.d.ts +7 -0
- package/dist/lib/auth/security-notifications/templates/password-changed.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/templates/password-changed.js +35 -0
- package/dist/lib/auth/security-notifications/templates/shared.d.ts +36 -0
- package/dist/lib/auth/security-notifications/templates/shared.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/templates/shared.js +68 -0
- package/dist/lib/auth/security-notifications/types.d.ts +74 -0
- package/dist/lib/auth/security-notifications/types.d.ts.map +1 -0
- package/dist/lib/auth/security-notifications/types.js +0 -0
- package/dist/lib/auth/session-config.d.ts +37 -0
- package/dist/lib/auth/session-config.d.ts.map +1 -0
- package/dist/lib/auth/session-config.js +59 -0
- package/dist/lib/auth/session-refresh.d.ts +46 -0
- package/dist/lib/auth/session-refresh.d.ts.map +1 -0
- package/dist/lib/auth/session-refresh.js +11 -0
- package/dist/lib/auth-client.d.ts +1489 -3445
- package/dist/lib/auth-client.d.ts.map +1 -1
- package/dist/lib/auth-client.js +4 -0
- package/dist/lib/auth.d.ts +1 -3057
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +21 -8
- package/dist/lib/billing/gateways/factory.d.ts +8 -3
- package/dist/lib/billing/gateways/factory.d.ts.map +1 -1
- package/dist/lib/billing/gateways/factory.js +37 -23
- package/dist/lib/billing/schema.d.ts +1 -1
- package/dist/lib/billing/stripe-webhook.d.ts.map +1 -1
- package/dist/lib/billing/stripe-webhook.js +2 -1
- package/dist/lib/config/app.config.d.ts.map +1 -1
- package/dist/lib/config/app.config.js +71 -0
- package/dist/lib/config/config-sync.d.ts +1 -4
- package/dist/lib/config/config-sync.d.ts.map +1 -1
- package/dist/lib/config/config-sync.js +6 -2
- package/dist/lib/config/types.d.ts +130 -0
- package/dist/lib/config/types.d.ts.map +1 -1
- package/dist/lib/entities/entity-hooks.d.ts +9 -1
- package/dist/lib/entities/entity-hooks.d.ts.map +1 -1
- package/dist/lib/entities/entity-hooks.js +77 -4
- package/dist/lib/entities/schema-generator.d.ts.map +1 -1
- package/dist/lib/entities/schema-generator.js +20 -4
- package/dist/lib/entities/serialization.d.ts +2 -2
- package/dist/lib/entities/serialization.d.ts.map +1 -1
- package/dist/lib/entities/serialization.js +3 -2
- package/dist/lib/entities/types.d.ts +8 -0
- package/dist/lib/entities/types.d.ts.map +1 -1
- package/dist/lib/locale.d.ts.map +1 -1
- package/dist/lib/locale.js +4 -1
- package/dist/lib/mcp/audit.d.ts +21 -0
- package/dist/lib/mcp/audit.d.ts.map +1 -0
- package/dist/lib/mcp/audit.js +48 -0
- package/dist/lib/mcp/engine.d.ts +28 -0
- package/dist/lib/mcp/engine.d.ts.map +1 -0
- package/dist/lib/mcp/engine.js +158 -0
- package/dist/lib/mcp/errors.d.ts +16 -0
- package/dist/lib/mcp/errors.d.ts.map +1 -0
- package/dist/lib/mcp/errors.js +66 -0
- package/dist/lib/mcp/executor.d.ts +15 -0
- package/dist/lib/mcp/executor.d.ts.map +1 -0
- package/dist/lib/mcp/executor.js +63 -0
- package/dist/lib/mcp/index.d.ts +9 -0
- package/dist/lib/mcp/index.d.ts.map +1 -0
- package/dist/lib/mcp/index.js +32 -0
- package/dist/lib/mcp/schema-builder.d.ts +45 -0
- package/dist/lib/mcp/schema-builder.d.ts.map +1 -0
- package/dist/lib/mcp/schema-builder.js +212 -0
- package/dist/lib/mcp/tool-generator.d.ts +31 -0
- package/dist/lib/mcp/tool-generator.d.ts.map +1 -0
- package/dist/lib/mcp/tool-generator.js +271 -0
- package/dist/lib/mcp/transport.d.ts +31 -0
- package/dist/lib/mcp/transport.d.ts.map +1 -0
- package/dist/lib/mcp/transport.js +58 -0
- package/dist/lib/mcp/types.d.ts +184 -0
- package/dist/lib/mcp/types.d.ts.map +1 -0
- package/dist/lib/mcp/types.js +11 -0
- package/dist/lib/plugins/hook-system.d.ts +13 -0
- package/dist/lib/plugins/hook-system.d.ts.map +1 -1
- package/dist/lib/plugins/hook-system.js +32 -2
- package/dist/lib/scheduled-actions/handlers/index.d.ts +1 -0
- package/dist/lib/scheduled-actions/handlers/index.d.ts.map +1 -1
- package/dist/lib/scheduled-actions/handlers/index.js +3 -1
- package/dist/lib/scheduled-actions/handlers/security-notification.d.ts +26 -0
- package/dist/lib/scheduled-actions/handlers/security-notification.d.ts.map +1 -0
- package/dist/lib/scheduled-actions/handlers/security-notification.js +54 -0
- package/dist/lib/selectors/core-selectors.d.ts +12 -0
- package/dist/lib/selectors/core-selectors.d.ts.map +1 -1
- package/dist/lib/selectors/domains/auth.selectors.d.ts +12 -0
- package/dist/lib/selectors/domains/auth.selectors.d.ts.map +1 -1
- package/dist/lib/selectors/domains/auth.selectors.js +14 -1
- package/dist/lib/selectors/selectors.d.ts +24 -0
- package/dist/lib/selectors/selectors.d.ts.map +1 -1
- package/dist/lib/services/generic-entity.service.d.ts.map +1 -1
- package/dist/lib/services/generic-entity.service.js +16 -32
- package/dist/lib/services/membership.service.d.ts +10 -2
- package/dist/lib/services/membership.service.d.ts.map +1 -1
- package/dist/lib/services/membership.service.js +37 -16
- package/dist/lib/services/subscription.service.d.ts.map +1 -1
- package/dist/lib/services/subscription.service.js +2 -1
- package/dist/lib/services/team-member.service.d.ts +15 -3
- package/dist/lib/services/team-member.service.d.ts.map +1 -1
- package/dist/lib/services/team-member.service.js +27 -6
- package/dist/lib/services/team.service.d.ts.map +1 -1
- package/dist/lib/teams/permissions.d.ts +3 -1
- package/dist/lib/teams/permissions.d.ts.map +1 -1
- package/dist/lib/teams/permissions.js +6 -0
- package/dist/lib/teams/schema.d.ts.map +1 -1
- package/dist/lib/teams/schema.js +3 -0
- package/dist/lib/theme/forced-theme.d.ts +34 -0
- package/dist/lib/theme/forced-theme.d.ts.map +1 -0
- package/dist/lib/theme/forced-theme.js +27 -0
- package/dist/lib/theme/get-default-theme-mode.d.ts +3 -0
- package/dist/lib/theme/get-default-theme-mode.d.ts.map +1 -1
- package/dist/lib/theme/get-default-theme-mode.js +5 -3
- package/dist/messages/de/auth.json +25 -2
- package/dist/messages/de/index.d.ts +81 -0
- package/dist/messages/de/index.d.ts.map +1 -1
- package/dist/messages/de/index.js +2 -0
- package/dist/messages/de/index.ts +2 -0
- package/dist/messages/en/auth.json +25 -2
- package/dist/messages/en/index.d.ts +81 -0
- package/dist/messages/en/index.d.ts.map +1 -1
- package/dist/messages/en/index.js +2 -0
- package/dist/messages/en/index.ts +2 -0
- package/dist/messages/es/auth.json +25 -2
- package/dist/messages/es/index.d.ts +81 -0
- package/dist/messages/es/index.d.ts.map +1 -1
- package/dist/messages/es/index.js +2 -0
- package/dist/messages/es/index.ts +2 -0
- package/dist/messages/fr/auth.json +25 -2
- package/dist/messages/fr/index.d.ts +81 -0
- package/dist/messages/fr/index.d.ts.map +1 -1
- package/dist/messages/fr/index.js +2 -0
- package/dist/messages/fr/index.ts +2 -0
- package/dist/messages/it/auth.json +25 -2
- package/dist/messages/it/index.d.ts +81 -0
- package/dist/messages/it/index.d.ts.map +1 -1
- package/dist/messages/it/index.js +2 -0
- package/dist/messages/it/index.ts +2 -0
- package/dist/messages/pt/auth.json +25 -2
- package/dist/messages/pt/index.d.ts +81 -0
- package/dist/messages/pt/index.d.ts.map +1 -1
- package/dist/messages/pt/index.js +2 -0
- package/dist/messages/pt/index.ts +2 -0
- package/dist/migrations/005_api_audit_log.sql +2 -1
- package/dist/migrations/025_api_audit_log_nullable_api_key.sql +12 -0
- package/dist/migrations/026_login_events.sql +91 -0
- package/dist/migrations/027_rls_bypass_developer_and_system_admin_team.sql +197 -0
- package/dist/providers/DashboardProviders.d.ts +12 -3
- package/dist/providers/DashboardProviders.d.ts.map +1 -1
- package/dist/providers/DashboardProviders.js +6 -2
- package/dist/providers/theme-provider.d.ts +19 -2
- package/dist/providers/theme-provider.d.ts.map +1 -1
- package/dist/providers/theme-provider.js +6 -2
- package/dist/templates/app/(auth)/signup/page.tsx +8 -0
- package/dist/templates/app/(public)/[...slug]/page.tsx +9 -14
- package/dist/templates/app/api/auth/[...all]/route.ts +23 -1
- package/dist/templates/app/api/health/route.ts +4 -2
- package/dist/templates/app/api/internal/user-metadata/route.ts +5 -3
- package/dist/templates/app/api/mcp/route.ts +176 -0
- package/dist/templates/app/api/superadmin/subscriptions/route.ts +2 -1
- package/dist/templates/app/api/superadmin/teams/[teamId]/route.ts +4 -3
- package/dist/templates/app/api/superadmin/users/[userId]/route.ts +10 -3
- package/dist/templates/app/api/v1/api-keys/[id]/route.ts +50 -71
- package/dist/templates/app/api/v1/api-keys/route.ts +35 -45
- package/dist/templates/app/api/v1/auth/signup-with-invite/route.ts +14 -14
- package/dist/templates/app/api/v1/billing/cancel/route.ts +7 -6
- package/dist/templates/app/api/v1/billing/change-plan/route.ts +5 -4
- package/dist/templates/app/api/v1/billing/check-action/route.ts +6 -4
- package/dist/templates/app/api/v1/billing/checkout/route.ts +7 -5
- package/dist/templates/app/api/v1/billing/plans/route.ts +8 -12
- package/dist/templates/app/api/v1/billing/portal/route.ts +7 -5
- package/dist/templates/app/api/v1/billing/webhooks/polar/route.ts +1 -1
- package/dist/templates/app/api/v1/devtools/blocks/route.ts +5 -4
- package/dist/templates/app/api/v1/devtools/features/route.ts +5 -4
- package/dist/templates/app/api/v1/devtools/flows/route.ts +5 -4
- package/dist/templates/app/api/v1/devtools/scheduled-actions/route.ts +9 -7
- package/dist/templates/app/api/v1/devtools/scheduled-actions/run/route.ts +5 -4
- package/dist/templates/app/api/v1/devtools/testing/route.ts +5 -4
- package/dist/templates/app/api/v1/media/[id]/route.ts +13 -25
- package/dist/templates/app/api/v1/media/[id]/tags/route.ts +17 -25
- package/dist/templates/app/api/v1/media/check-duplicates/route.ts +5 -7
- package/dist/templates/app/api/v1/media/route.ts +5 -9
- package/dist/templates/app/api/v1/media/upload/route.ts +9 -21
- package/dist/templates/app/api/v1/media-tags/route.ts +9 -13
- package/dist/templates/app/api/v1/patterns/[id]/usages/route.ts +11 -19
- package/dist/templates/app/api/v1/post-categories/[id]/route.ts +9 -7
- package/dist/templates/app/api/v1/post-categories/route.ts +5 -4
- package/dist/templates/app/api/v1/team-invitations/[token]/accept/route.ts +16 -18
- package/dist/templates/app/api/v1/team-invitations/[token]/decline/route.ts +15 -17
- package/dist/templates/app/api/v1/team-invitations/[token]/route.ts +8 -8
- package/dist/templates/app/api/v1/team-invitations/route.ts +9 -11
- package/dist/templates/app/api/v1/teams/[teamId]/invitations/route.ts +41 -32
- package/dist/templates/app/api/v1/teams/[teamId]/invoices/[invoiceNumber]/route.ts +15 -16
- package/dist/templates/app/api/v1/teams/[teamId]/invoices/route.ts +14 -15
- package/dist/templates/app/api/v1/teams/[teamId]/members/[memberId]/route.ts +32 -36
- package/dist/templates/app/api/v1/teams/[teamId]/members/route.ts +33 -33
- package/dist/templates/app/api/v1/teams/[teamId]/route.ts +35 -41
- package/dist/templates/app/api/v1/teams/[teamId]/subscription/route.ts +5 -3
- package/dist/templates/app/api/v1/teams/[teamId]/usage/[limitSlug]/route.ts +10 -6
- package/dist/templates/app/api/v1/teams/route.ts +33 -27
- package/dist/templates/app/api/v1/teams/switch/route.ts +11 -13
- package/dist/templates/app/api/v1/theme/[...path]/route.ts +23 -2
- package/dist/templates/app/api/v1/users/[id]/meta/[key]/route.ts +32 -77
- package/dist/templates/app/api/v1/users/[id]/route.ts +35 -68
- package/dist/templates/app/api/v1/users/route.ts +21 -25
- package/dist/templates/app/dashboard/layout.tsx +2 -6
- package/dist/templates/app/layout.ppr.tsx +9 -14
- package/dist/templates/app/layout.tsx +39 -19
- package/dist/templates/contents/themes/starter/config/app.config.ts +19 -0
- package/dist/templates/contents/themes/starter/config/theme.config.ts +6 -0
- package/dist/templates/contents/themes/starter/styles/globals.css +6 -2
- package/dist/templates/proxy.ts +46 -10
- package/dist/templates/tsconfig.json +4 -0
- package/dist/types/theme.d.ts +9 -0
- package/dist/types/theme.d.ts.map +1 -1
- package/migrations/005_api_audit_log.sql +2 -1
- package/migrations/025_api_audit_log_nullable_api_key.sql +12 -0
- package/migrations/026_login_events.sql +91 -0
- package/migrations/027_rls_bypass_developer_and_system_admin_team.sql +197 -0
- package/package.json +20 -12
- package/scripts/build/registry/__tests__/mcp-registry.test.mjs +64 -0
- package/scripts/build/registry/__tests__/scope-registry.test.mjs +106 -0
- package/scripts/build/registry/discovery/mcp-overrides.mjs +72 -0
- package/scripts/build/registry/discovery/mcp-overrides.test.mjs +86 -0
- package/scripts/build/registry/generators/mcp-registry.mjs +61 -0
- package/scripts/build/registry/generators/scope-registry.mjs +140 -88
- package/scripts/build/registry.mjs +8 -4
- package/templates/app/(auth)/signup/page.tsx +8 -0
- package/templates/app/(public)/[...slug]/page.tsx +9 -14
- package/templates/app/api/auth/[...all]/route.ts +23 -1
- package/templates/app/api/health/route.ts +4 -2
- package/templates/app/api/internal/user-metadata/route.ts +5 -3
- package/templates/app/api/mcp/route.ts +176 -0
- package/templates/app/api/superadmin/subscriptions/route.ts +2 -1
- package/templates/app/api/superadmin/teams/[teamId]/route.ts +4 -3
- package/templates/app/api/superadmin/users/[userId]/route.ts +10 -3
- package/templates/app/api/v1/api-keys/[id]/route.ts +50 -71
- package/templates/app/api/v1/api-keys/route.ts +35 -45
- package/templates/app/api/v1/auth/signup-with-invite/route.ts +14 -14
- package/templates/app/api/v1/billing/cancel/route.ts +7 -6
- package/templates/app/api/v1/billing/change-plan/route.ts +5 -4
- package/templates/app/api/v1/billing/check-action/route.ts +6 -4
- package/templates/app/api/v1/billing/checkout/route.ts +7 -5
- package/templates/app/api/v1/billing/plans/route.ts +8 -12
- package/templates/app/api/v1/billing/portal/route.ts +7 -5
- package/templates/app/api/v1/billing/webhooks/polar/route.ts +1 -1
- package/templates/app/api/v1/devtools/blocks/route.ts +5 -4
- package/templates/app/api/v1/devtools/features/route.ts +5 -4
- package/templates/app/api/v1/devtools/flows/route.ts +5 -4
- package/templates/app/api/v1/devtools/scheduled-actions/route.ts +9 -7
- package/templates/app/api/v1/devtools/scheduled-actions/run/route.ts +5 -4
- package/templates/app/api/v1/devtools/testing/route.ts +5 -4
- package/templates/app/api/v1/media/[id]/route.ts +13 -25
- package/templates/app/api/v1/media/[id]/tags/route.ts +17 -25
- package/templates/app/api/v1/media/check-duplicates/route.ts +5 -7
- package/templates/app/api/v1/media/route.ts +5 -9
- package/templates/app/api/v1/media/upload/route.ts +9 -21
- package/templates/app/api/v1/media-tags/route.ts +9 -13
- package/templates/app/api/v1/patterns/[id]/usages/route.ts +11 -19
- package/templates/app/api/v1/post-categories/[id]/route.ts +9 -7
- package/templates/app/api/v1/post-categories/route.ts +5 -4
- package/templates/app/api/v1/team-invitations/[token]/accept/route.ts +16 -18
- package/templates/app/api/v1/team-invitations/[token]/decline/route.ts +15 -17
- package/templates/app/api/v1/team-invitations/[token]/route.ts +8 -8
- package/templates/app/api/v1/team-invitations/route.ts +9 -11
- package/templates/app/api/v1/teams/[teamId]/invitations/route.ts +41 -32
- package/templates/app/api/v1/teams/[teamId]/invoices/[invoiceNumber]/route.ts +15 -16
- package/templates/app/api/v1/teams/[teamId]/invoices/route.ts +14 -15
- package/templates/app/api/v1/teams/[teamId]/members/[memberId]/route.ts +32 -36
- package/templates/app/api/v1/teams/[teamId]/members/route.ts +33 -33
- package/templates/app/api/v1/teams/[teamId]/route.ts +35 -41
- package/templates/app/api/v1/teams/[teamId]/subscription/route.ts +5 -3
- package/templates/app/api/v1/teams/[teamId]/usage/[limitSlug]/route.ts +10 -6
- package/templates/app/api/v1/teams/route.ts +33 -27
- package/templates/app/api/v1/teams/switch/route.ts +11 -13
- package/templates/app/api/v1/theme/[...path]/route.ts +23 -2
- package/templates/app/api/v1/users/[id]/meta/[key]/route.ts +32 -77
- package/templates/app/api/v1/users/[id]/route.ts +35 -68
- package/templates/app/api/v1/users/route.ts +21 -25
- package/templates/app/dashboard/layout.tsx +2 -6
- package/templates/app/layout.ppr.tsx +9 -14
- package/templates/app/layout.tsx +39 -19
- package/templates/contents/themes/starter/config/app.config.ts +19 -0
- package/templates/contents/themes/starter/config/theme.config.ts +6 -0
- package/templates/contents/themes/starter/styles/globals.css +6 -2
- package/templates/proxy.ts +46 -10
- package/templates/tsconfig.json +4 -0
- package/tests/jest/__mocks__/@nextsparkjs/registries/permissions-registry.ts +23 -0
- package/tests/jest/__mocks__/@nextsparkjs/registries/scope-registry.ts +56 -6
- package/tests/jest/__mocks__/next-server.js +24 -0
- package/dist/styles/classes.json +0 -1093
- package/dist/styles/ui.css +0 -2
- package/scripts/build/build-ui-css.mjs +0 -351
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* 2. Falls back to default PageRenderer if no template
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { Suspense } from 'react'
|
|
17
16
|
import { notFound } from 'next/navigation'
|
|
18
17
|
import { query } from '@nextsparkjs/core/lib/db'
|
|
19
18
|
import { PageRenderer } from '@nextsparkjs/core/components/public/pageBuilder'
|
|
@@ -249,9 +248,16 @@ export async function generateMetadata({
|
|
|
249
248
|
}
|
|
250
249
|
|
|
251
250
|
/**
|
|
252
|
-
* Main catch-all page
|
|
251
|
+
* Main catch-all page component
|
|
252
|
+
*
|
|
253
|
+
* Not wrapped in Suspense: this route's entire content depends on whether the
|
|
254
|
+
* slug resolves to a published item, so notFound() must be able to run before
|
|
255
|
+
* any part of the response commits to a 200. A Suspense boundary here would
|
|
256
|
+
* let Next.js flush the (null) fallback with a 200 status ahead of the
|
|
257
|
+
* DB-backed lookup, so a later notFound() inside the boundary could no longer
|
|
258
|
+
* change the status code — see #129.
|
|
253
259
|
*/
|
|
254
|
-
async function
|
|
260
|
+
export default async function DynamicPublicPage({
|
|
255
261
|
params,
|
|
256
262
|
searchParams,
|
|
257
263
|
}: PageProps) {
|
|
@@ -378,14 +384,3 @@ async function DynamicPublicPageContent({
|
|
|
378
384
|
// No match found
|
|
379
385
|
notFound()
|
|
380
386
|
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Main catch-all page component — wraps async content in Suspense for PPR compatibility
|
|
384
|
-
*/
|
|
385
|
-
export default function DynamicPublicPage(props: PageProps) {
|
|
386
|
-
return (
|
|
387
|
-
<Suspense fallback={null}>
|
|
388
|
-
<DynamicPublicPageContent {...props} />
|
|
389
|
-
</Suspense>
|
|
390
|
-
)
|
|
391
|
-
}
|
|
@@ -9,6 +9,7 @@ import { TeamService } from "@nextsparkjs/core/lib/services";
|
|
|
9
9
|
import { wrapAuthHandlerWithCors, handleCorsPreflightRequest, addCorsHeaders } from "@nextsparkjs/core/lib/api/helpers";
|
|
10
10
|
import { checkDistributedRateLimit } from "@nextsparkjs/core/lib/api/rate-limit";
|
|
11
11
|
import { withSignupContext } from "@nextsparkjs/core/lib/auth-context";
|
|
12
|
+
import { dispatchSecurityNotificationsForRequest } from "@nextsparkjs/core/lib/auth/security-notifications";
|
|
12
13
|
|
|
13
14
|
const handlers = toNextJsHandler(auth);
|
|
14
15
|
|
|
@@ -181,11 +182,32 @@ export async function POST(req: NextRequest) {
|
|
|
181
182
|
? (req.cookies.get('signup-intent')?.value || undefined)
|
|
182
183
|
: undefined;
|
|
183
184
|
|
|
185
|
+
// Clone the request BEFORE the handler consumes its body. The
|
|
186
|
+
// security-notifications dispatcher (below) needs the original request's
|
|
187
|
+
// headers (UA/IP) and, for change-email, its body (newEmail) — but
|
|
188
|
+
// handlers.POST(req) reads req's body exactly once.
|
|
189
|
+
const securityReq = req.clone() as NextRequest;
|
|
190
|
+
|
|
184
191
|
// Wrap with CORS headers for cross-origin requests (mobile apps, etc.)
|
|
185
|
-
|
|
192
|
+
const response = await wrapAuthHandlerWithCors(
|
|
186
193
|
signupIntent
|
|
187
194
|
? () => withSignupContext({ signupIntent }, () => handlers.POST(req))
|
|
188
195
|
: () => handlers.POST(req),
|
|
189
196
|
req
|
|
190
197
|
);
|
|
198
|
+
|
|
199
|
+
// Built-in security email notifications (issue #75): after a successful
|
|
200
|
+
// sign-in / change-password / change-email, queue the matching security
|
|
201
|
+
// email. Guarded by AUTH_CONFIG.securityNotifications.enabled and wrapped in
|
|
202
|
+
// try/catch — a notification failure must NEVER change the auth response
|
|
203
|
+
// status (the dispatcher is itself best-effort, this is defense in depth).
|
|
204
|
+
if (AUTH_CONFIG.securityNotifications?.enabled) {
|
|
205
|
+
try {
|
|
206
|
+
await dispatchSecurityNotificationsForRequest(securityReq, response);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
console.error("[auth] security-notifications dispatch error:", error);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return response;
|
|
191
213
|
}
|
|
@@ -24,8 +24,10 @@ export const GET = withRateLimitTier(async (request: NextRequest) => {
|
|
|
24
24
|
timestamp: new Date().toISOString(),
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// Check if caller is authenticated for detailed info
|
|
28
|
-
|
|
27
|
+
// Check if caller is authenticated for detailed info. Public endpoint: any
|
|
28
|
+
// valid API key (whatever its scopes) may see the detailed status, so the
|
|
29
|
+
// scope-agnostic opt-out is explicit here (#93).
|
|
30
|
+
const authResult = await authenticateRequest(request, { allowAnyScope: true });
|
|
29
31
|
const isAuthenticated = authResult.success && authResult.user;
|
|
30
32
|
|
|
31
33
|
if (!isAuthenticated) {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server'
|
|
2
2
|
import { MetaService } from '@nextsparkjs/core/lib/services/meta.service'
|
|
3
3
|
import { withRateLimitTier } from '@nextsparkjs/core/lib/api/rate-limit'
|
|
4
|
-
import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
|
|
4
|
+
import { authenticateRequest, createAuthFailureResponse } from '@nextsparkjs/core/lib/api/auth/dual-auth'
|
|
5
5
|
|
|
6
6
|
// Endpoint interno para crear metadata default después del signup
|
|
7
7
|
export const POST = withRateLimitTier(async (req: NextRequest) => {
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
// The API-key scope is declared at the entry point, which fails closed
|
|
10
|
+
// for keys that lack it (#93).
|
|
11
|
+
const authResult = await authenticateRequest(req, { requiredScope: 'users:write' })
|
|
10
12
|
if (!authResult.success || !authResult.user) {
|
|
11
|
-
return
|
|
13
|
+
return createAuthFailureResponse(authResult)
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
const body = await req.json()
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP endpoint — POST /api/mcp (Streamable HTTP, stateless JSON mode).
|
|
3
|
+
*
|
|
4
|
+
* Auth: API key ONLY (Authorization: Bearer sk_... or x-api-key). Session
|
|
5
|
+
* cookies are rejected — this endpoint is for MCP clients, not browsers.
|
|
6
|
+
* authenticateRequest runs ONCE here; the resolved identity, team context and
|
|
7
|
+
* api_key id travel to every tool via ToolExecutionContext.
|
|
8
|
+
*
|
|
9
|
+
* Tools and overrides are entirely registry-driven: every access.api-enabled
|
|
10
|
+
* entity in ENTITY_REGISTRY becomes a set of tools automatically, and any
|
|
11
|
+
* `entities/<slug>/mcp.ts` a theme defines is picked up via the generated
|
|
12
|
+
* MCP_OVERRIDES registry — no per-app hand-wiring required.
|
|
13
|
+
*
|
|
14
|
+
* Security posture:
|
|
15
|
+
* - kill-switch: MCP_ENABLED (dev: on unless 'false'; production: OFF unless 'true')
|
|
16
|
+
* - Origin validated when present (DNS-rebinding protection); no CORS reflection
|
|
17
|
+
* - rate limit: tier 'api' — with the in-process executor this is the ONLY
|
|
18
|
+
* rate limit on the whole MCP surface (deploy prerequisite: Redis)
|
|
19
|
+
* - team-role permissions + scopes + ownership/field guards come from the
|
|
20
|
+
* real generic entity handlers the executor calls in-process (#94/#95)
|
|
21
|
+
* - every tool call is audited to api_audit_log
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
25
|
+
import {
|
|
26
|
+
authenticateRequest,
|
|
27
|
+
resolveTeamContext,
|
|
28
|
+
} from '@nextsparkjs/core/lib/api/auth/dual-auth'
|
|
29
|
+
import { validateApiKey } from '@nextsparkjs/core/lib/api/auth'
|
|
30
|
+
import { withRateLimitTier } from '@nextsparkjs/core/lib/api/rate-limit'
|
|
31
|
+
import { setEntityRegistry } from '@nextsparkjs/core/lib/entities/queries'
|
|
32
|
+
import { createMcpEngine } from '@nextsparkjs/core/lib/mcp'
|
|
33
|
+
import type { ToolExecutionContext } from '@nextsparkjs/core/lib/mcp'
|
|
34
|
+
import type { EntityConfig } from '@nextsparkjs/core/lib/entities/types'
|
|
35
|
+
// Import registries directly - webpack resolves @nextsparkjs/registries alias at compile time
|
|
36
|
+
import { ENTITY_REGISTRY, ENTITY_METADATA } from '@nextsparkjs/registries/entity-registry'
|
|
37
|
+
import { MCP_OVERRIDES } from '@nextsparkjs/registries/mcp-registry'
|
|
38
|
+
import { API_PRESETS_REGISTRY } from '@nextsparkjs/registries/api-presets-registry'
|
|
39
|
+
|
|
40
|
+
// Initialize registry at module load time (before any handler runs)
|
|
41
|
+
setEntityRegistry(ENTITY_REGISTRY, ENTITY_METADATA)
|
|
42
|
+
|
|
43
|
+
// Registry entries are wrappers ({ name, config, tableName, ... }) — the
|
|
44
|
+
// engine consumes the EntityConfig map.
|
|
45
|
+
const entityConfigs = Object.fromEntries(
|
|
46
|
+
Object.entries(ENTITY_REGISTRY as Record<string, { config: EntityConfig }>).map(
|
|
47
|
+
([slug, entry]) => [slug, entry.config]
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
// Tool descriptions are seeded from api/presets.ts (summary → entity
|
|
52
|
+
// description, presets → few-shot examples) — the same registry the API
|
|
53
|
+
// Explorer already uses, keyed by endpoint instead of slug here.
|
|
54
|
+
const presetsBySlug = Object.fromEntries(
|
|
55
|
+
Object.entries(API_PRESETS_REGISTRY.endpoints ?? {}).map(([endpoint, data]) => [
|
|
56
|
+
endpoint.replace(/^\/api\/v1\//, ''),
|
|
57
|
+
{ summary: data.summary, presets: data.presets },
|
|
58
|
+
])
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const toolPrefix = (process.env.MCP_TOOL_PREFIX || process.env.NEXT_PUBLIC_ACTIVE_THEME || 'app')
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
64
|
+
.replace(/^_+|_+$/g, '')
|
|
65
|
+
|
|
66
|
+
const engine = createMcpEngine(entityConfigs, {
|
|
67
|
+
toolPrefix,
|
|
68
|
+
overrides: MCP_OVERRIDES,
|
|
69
|
+
presets: presetsBySlug,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const API_KEY_HELP =
|
|
73
|
+
'This endpoint requires an API key: generate one in Settings → API Keys and configure it in your MCP client as the header "Authorization: Bearer sk_...".'
|
|
74
|
+
|
|
75
|
+
function isMcpEnabled(): boolean {
|
|
76
|
+
const flag = process.env.MCP_ENABLED
|
|
77
|
+
if (process.env.NODE_ENV === 'production') return flag === 'true'
|
|
78
|
+
return flag !== 'false'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isOriginAllowed(request: NextRequest): boolean {
|
|
82
|
+
const origin = request.headers.get('origin')
|
|
83
|
+
if (!origin) return true // non-browser MCP clients don't send Origin
|
|
84
|
+
const allowed = new Set(
|
|
85
|
+
[request.nextUrl.origin, process.env.NEXT_PUBLIC_APP_URL, process.env.BETTER_AUTH_URL].filter(
|
|
86
|
+
Boolean
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
return allowed.has(origin)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function jsonRpcError(
|
|
93
|
+
status: number,
|
|
94
|
+
code: number,
|
|
95
|
+
message: string,
|
|
96
|
+
id: string | number | null = null
|
|
97
|
+
): NextResponse {
|
|
98
|
+
return NextResponse.json({ jsonrpc: '2.0', error: { code, message }, id }, { status })
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function handleMcpPost(request: NextRequest): Promise<NextResponse> {
|
|
102
|
+
if (!isMcpEnabled()) {
|
|
103
|
+
return NextResponse.json({ error: 'Not found' }, { status: 404 })
|
|
104
|
+
}
|
|
105
|
+
if (!isOriginAllowed(request)) {
|
|
106
|
+
return jsonRpcError(403, -32000, 'Origin not allowed')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Transport-level auth only: per-tool scopes (`<entity>:read/write/delete`)
|
|
110
|
+
// are enforced by the generic entity handlers the executor invokes for each
|
|
111
|
+
// tool call, so this entry point accepts any valid key explicitly (#93).
|
|
112
|
+
const authResult = await authenticateRequest(request, { allowAnyScope: true })
|
|
113
|
+
if (!authResult.success || authResult.type !== 'api-key' || !authResult.user) {
|
|
114
|
+
return jsonRpcError(401, -32001, API_KEY_HELP)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Same cached lookup the auth already did — needed for the audit trail.
|
|
118
|
+
const apiKeyAuth = await validateApiKey(request)
|
|
119
|
+
|
|
120
|
+
const teamResult = await resolveTeamContext(request, authResult)
|
|
121
|
+
if (teamResult instanceof Response) {
|
|
122
|
+
const status = teamResult.status
|
|
123
|
+
return jsonRpcError(
|
|
124
|
+
status,
|
|
125
|
+
-32002,
|
|
126
|
+
status === 403
|
|
127
|
+
? 'The API key user is not a member of the team specified in x-team-id.'
|
|
128
|
+
: 'Could not resolve the user team. Send the x-team-id header or assign a default team.'
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let body: unknown
|
|
133
|
+
try {
|
|
134
|
+
body = await request.json()
|
|
135
|
+
} catch {
|
|
136
|
+
return jsonRpcError(400, -32700, 'Parse error: body must be JSON-RPC')
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const ctx: ToolExecutionContext = {
|
|
140
|
+
userId: authResult.user.id,
|
|
141
|
+
userRole: authResult.user.role,
|
|
142
|
+
teamId: teamResult,
|
|
143
|
+
authHeader:
|
|
144
|
+
request.headers.get('authorization') ?? `Bearer ${request.headers.get('x-api-key') ?? ''}`,
|
|
145
|
+
apiKeyId: apiKeyAuth?.keyId ?? null,
|
|
146
|
+
scopes: authResult.scopes ?? [],
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const result = await engine.handleJsonRpc(body, ctx)
|
|
151
|
+
if (result === null) {
|
|
152
|
+
// Notification(s) only — accepted, nothing to return.
|
|
153
|
+
return new NextResponse(null, { status: 202 })
|
|
154
|
+
}
|
|
155
|
+
return NextResponse.json(result, { status: 200 })
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error('[mcp] request failed:', error)
|
|
158
|
+
return jsonRpcError(500, -32603, 'Internal error processing MCP request')
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const POST = withRateLimitTier(handleMcpPost, 'api')
|
|
163
|
+
|
|
164
|
+
export async function GET(): Promise<NextResponse> {
|
|
165
|
+
return NextResponse.json(
|
|
166
|
+
{ error: 'Method not allowed. MCP requests must be POST (stateless JSON mode, no SSE).' },
|
|
167
|
+
{ status: 405, headers: { Allow: 'POST' } }
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function DELETE(): Promise<NextResponse> {
|
|
172
|
+
return NextResponse.json(
|
|
173
|
+
{ error: 'Method not allowed. This server is stateless: there is no session to delete.' },
|
|
174
|
+
{ status: 405, headers: { Allow: 'POST' } }
|
|
175
|
+
)
|
|
176
|
+
}
|
|
@@ -230,6 +230,7 @@ export const GET = withRateLimitTier(async (request: NextRequest) => {
|
|
|
230
230
|
const totalPages = Math.ceil(total / limit);
|
|
231
231
|
|
|
232
232
|
// Format subscriptions
|
|
233
|
+
const billingGateway = await getBillingGateway()
|
|
233
234
|
const subscriptions = subscriptionsResult.map(sub => ({
|
|
234
235
|
id: sub.id,
|
|
235
236
|
team: {
|
|
@@ -257,7 +258,7 @@ export const GET = withRateLimitTier(async (request: NextRequest) => {
|
|
|
257
258
|
cancelAtPeriodEnd: sub.cancelAtPeriodEnd,
|
|
258
259
|
externalSubscriptionId: sub.externalSubscriptionId,
|
|
259
260
|
paymentProvider: sub.paymentProvider,
|
|
260
|
-
providerDashboardUrl:
|
|
261
|
+
providerDashboardUrl: billingGateway.getSubscriptionDashboardUrl(sub.externalSubscriptionId),
|
|
261
262
|
createdAt: sub.createdAt
|
|
262
263
|
}));
|
|
263
264
|
|
|
@@ -204,6 +204,7 @@ export const GET = withRateLimitTier(async (
|
|
|
204
204
|
const subscription = subscriptionResult[0] || null;
|
|
205
205
|
|
|
206
206
|
// Prepare response data
|
|
207
|
+
const billingGateway = subscription ? await getBillingGateway() : null
|
|
207
208
|
const responseData = {
|
|
208
209
|
team: {
|
|
209
210
|
id: team.id,
|
|
@@ -225,7 +226,7 @@ export const GET = withRateLimitTier(async (
|
|
|
225
226
|
role: member.role,
|
|
226
227
|
joinedAt: member.joinedAt
|
|
227
228
|
})),
|
|
228
|
-
subscription: subscription ? {
|
|
229
|
+
subscription: subscription && billingGateway ? {
|
|
229
230
|
id: subscription.id,
|
|
230
231
|
plan: {
|
|
231
232
|
id: subscription.planId,
|
|
@@ -246,8 +247,8 @@ export const GET = withRateLimitTier(async (
|
|
|
246
247
|
externalSubscriptionId: subscription.externalSubscriptionId,
|
|
247
248
|
externalCustomerId: subscription.externalCustomerId,
|
|
248
249
|
paymentProvider: subscription.paymentProvider,
|
|
249
|
-
providerName:
|
|
250
|
-
providerDashboardUrl:
|
|
250
|
+
providerName: billingGateway.getProviderName(),
|
|
251
|
+
providerDashboardUrl: billingGateway.getSubscriptionDashboardUrl(subscription.externalSubscriptionId),
|
|
251
252
|
createdAt: subscription.createdAt
|
|
252
253
|
} : null,
|
|
253
254
|
billingHistory: billingEventsResult.map((event) => ({
|
|
@@ -129,11 +129,18 @@ export const GET = withRateLimitTier(async (request: NextRequest, { params }: Ro
|
|
|
129
129
|
ORDER BY "metaKey"
|
|
130
130
|
`;
|
|
131
131
|
|
|
132
|
-
// Execute all queries in parallel
|
|
132
|
+
// Execute all queries in parallel.
|
|
133
|
+
//
|
|
134
|
+
// The team_members queries run on the service (RLS-bypass) pool: team_members
|
|
135
|
+
// has no superadmin/developer bypass policy, so with the acting admin's own
|
|
136
|
+
// id as RLS context the SELECT policy silently ANDs "teams the actor belongs
|
|
137
|
+
// to" on top of WHERE "userId" = $1 and under-reports multi-team users.
|
|
138
|
+
// Authorization is already enforced above (superadmin/developer role check)
|
|
139
|
+
// and the WHERE clause scopes the rows to the subject user.
|
|
133
140
|
const [userResults, teamsResults, countsResults, metasResults] = await Promise.all([
|
|
134
141
|
queryWithRLS(userQuery, [userId], session.user.id) as Promise<UserResult[]>,
|
|
135
|
-
queryWithRLS(teamsQuery, [userId], session.user.id) as Promise<TeamMembershipResult[]>,
|
|
136
|
-
queryWithRLS(countsQuery, [userId], session.user.id) as Promise<{
|
|
142
|
+
queryWithRLS(teamsQuery, [userId], session.user.id, { service: true }) as Promise<TeamMembershipResult[]>,
|
|
143
|
+
queryWithRLS(countsQuery, [userId], session.user.id, { service: true }) as Promise<{
|
|
137
144
|
totalTeams: number;
|
|
138
145
|
ownedTeams: number;
|
|
139
146
|
}[]>,
|
|
@@ -20,12 +20,13 @@ import {
|
|
|
20
20
|
handleCorsPreflightRequest,
|
|
21
21
|
addCorsHeaders
|
|
22
22
|
} from '@nextsparkjs/core/lib/api/helpers';
|
|
23
|
-
import { authenticateRequest,
|
|
23
|
+
import { authenticateRequest, createAuthFailureResponse } from '@nextsparkjs/core/lib/api/auth/dual-auth';
|
|
24
|
+
import { invalidateApiKeyCache } from '@nextsparkjs/core/lib/api/auth';
|
|
24
25
|
import { withRateLimitTier } from '@nextsparkjs/core/lib/api/rate-limit';
|
|
25
26
|
|
|
26
27
|
// Handle CORS preflight
|
|
27
|
-
export async function OPTIONS() {
|
|
28
|
-
return handleCorsPreflightRequest();
|
|
28
|
+
export async function OPTIONS(request: NextRequest) {
|
|
29
|
+
return handleCorsPreflightRequest(request);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// GET /api/v1/api-keys/:id - Get specific API key details
|
|
@@ -34,34 +35,23 @@ export const GET = withRateLimitTier(withApiLogging(async (
|
|
|
34
35
|
{ params }: { params: Promise<{ id: string }> }
|
|
35
36
|
): Promise<NextResponse> => {
|
|
36
37
|
try {
|
|
37
|
-
// Authenticate using dual auth
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// Authenticate using dual auth; the API-key scope is declared at the entry
|
|
39
|
+
// point, which fails closed for keys that lack it (#93).
|
|
40
|
+
const authResult = await authenticateRequest(req, { requiredScope: 'admin:api-keys' });
|
|
41
|
+
|
|
40
42
|
if (!authResult.success) {
|
|
41
|
-
return
|
|
42
|
-
{ success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
|
|
43
|
-
{ status: 401 }
|
|
44
|
-
);
|
|
43
|
+
return createAuthFailureResponse(authResult);
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
if (authResult.rateLimitResponse) {
|
|
48
47
|
return authResult.rateLimitResponse as NextResponse;
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
// Check required permissions - session users have admin access, API key users need specific scope
|
|
52
|
-
const hasPermission = authResult.type === 'session' ||
|
|
53
|
-
(authResult.type === 'api-key' && hasRequiredScope(authResult, 'admin:api-keys'));
|
|
54
|
-
|
|
55
|
-
if (!hasPermission) {
|
|
56
|
-
const response = createApiError('Insufficient permissions. Admin access required for API key management.', 403);
|
|
57
|
-
return addCorsHeaders(response);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
50
|
const { id } = await params;
|
|
61
51
|
|
|
62
52
|
if (!id || id.trim() === '') {
|
|
63
53
|
const response = createApiError('API key ID is required', 400, null, 'MISSING_API_KEY_ID');
|
|
64
|
-
return addCorsHeaders(response);
|
|
54
|
+
return addCorsHeaders(response, req);
|
|
65
55
|
}
|
|
66
56
|
|
|
67
57
|
const apiKey = await queryOneWithRLS(
|
|
@@ -74,7 +64,7 @@ export const GET = withRateLimitTier(withApiLogging(async (
|
|
|
74
64
|
|
|
75
65
|
if (!apiKey) {
|
|
76
66
|
const response = createApiError('API key not found', 404, null, 'API_KEY_NOT_FOUND');
|
|
77
|
-
return addCorsHeaders(response);
|
|
67
|
+
return addCorsHeaders(response, req);
|
|
78
68
|
}
|
|
79
69
|
|
|
80
70
|
// Get detailed usage statistics
|
|
@@ -129,11 +119,11 @@ export const GET = withRateLimitTier(withApiLogging(async (
|
|
|
129
119
|
success_rate: null
|
|
130
120
|
}
|
|
131
121
|
});
|
|
132
|
-
return addCorsHeaders(response);
|
|
122
|
+
return addCorsHeaders(response, req);
|
|
133
123
|
} catch (error) {
|
|
134
124
|
console.error('Error fetching API key:', error);
|
|
135
125
|
const response = createApiError('Internal server error', 500);
|
|
136
|
-
return addCorsHeaders(response);
|
|
126
|
+
return addCorsHeaders(response, req);
|
|
137
127
|
}
|
|
138
128
|
}), 'strict');
|
|
139
129
|
|
|
@@ -143,34 +133,23 @@ export const PATCH = withRateLimitTier(withApiLogging(async (
|
|
|
143
133
|
{ params }: { params: Promise<{ id: string }> }
|
|
144
134
|
): Promise<NextResponse> => {
|
|
145
135
|
try {
|
|
146
|
-
// Authenticate using dual auth
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
// Authenticate using dual auth; the API-key scope is declared at the entry
|
|
137
|
+
// point, which fails closed for keys that lack it (#93).
|
|
138
|
+
const authResult = await authenticateRequest(req, { requiredScope: 'admin:api-keys' });
|
|
139
|
+
|
|
149
140
|
if (!authResult.success) {
|
|
150
|
-
return
|
|
151
|
-
{ success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
|
|
152
|
-
{ status: 401 }
|
|
153
|
-
);
|
|
141
|
+
return createAuthFailureResponse(authResult);
|
|
154
142
|
}
|
|
155
143
|
|
|
156
144
|
if (authResult.rateLimitResponse) {
|
|
157
145
|
return authResult.rateLimitResponse as NextResponse;
|
|
158
146
|
}
|
|
159
147
|
|
|
160
|
-
// Check required permissions - session users have admin access, API key users need specific scope
|
|
161
|
-
const hasPermission = authResult.type === 'session' ||
|
|
162
|
-
(authResult.type === 'api-key' && hasRequiredScope(authResult, 'admin:api-keys'));
|
|
163
|
-
|
|
164
|
-
if (!hasPermission) {
|
|
165
|
-
const response = createApiError('Insufficient permissions. Admin access required for API key management.', 403);
|
|
166
|
-
return addCorsHeaders(response);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
148
|
const { id } = await params;
|
|
170
149
|
|
|
171
150
|
if (!id || id.trim() === '') {
|
|
172
151
|
const response = createApiError('API key ID is required', 400, null, 'MISSING_API_KEY_ID');
|
|
173
|
-
return addCorsHeaders(response);
|
|
152
|
+
return addCorsHeaders(response, req);
|
|
174
153
|
}
|
|
175
154
|
|
|
176
155
|
const body = await req.json();
|
|
@@ -185,11 +164,11 @@ export const PATCH = withRateLimitTier(withApiLogging(async (
|
|
|
185
164
|
if (body[field] !== undefined) {
|
|
186
165
|
if (field === 'name' && typeof body[field] !== 'string') {
|
|
187
166
|
const response = createApiError('Name must be a string', 400, null, 'INVALID_NAME_TYPE');
|
|
188
|
-
return addCorsHeaders(response);
|
|
167
|
+
return addCorsHeaders(response, req);
|
|
189
168
|
}
|
|
190
169
|
if (field === 'status' && !['active', 'inactive', 'expired'].includes(body[field])) {
|
|
191
170
|
const response = createApiError('status must be active, inactive, or expired', 400, null, 'INVALID_STATUS_TYPE');
|
|
192
|
-
return addCorsHeaders(response);
|
|
171
|
+
return addCorsHeaders(response, req);
|
|
193
172
|
}
|
|
194
173
|
|
|
195
174
|
updates.push(`"${field}" = $${paramCount++}`);
|
|
@@ -199,7 +178,7 @@ export const PATCH = withRateLimitTier(withApiLogging(async (
|
|
|
199
178
|
|
|
200
179
|
if (updates.length === 0) {
|
|
201
180
|
const response = createApiError('No valid fields to update', 400, null, 'NO_FIELDS');
|
|
202
|
-
return addCorsHeaders(response);
|
|
181
|
+
return addCorsHeaders(response, req);
|
|
203
182
|
}
|
|
204
183
|
|
|
205
184
|
updates.push(`"updatedAt" = CURRENT_TIMESTAMP`);
|
|
@@ -209,22 +188,28 @@ export const PATCH = withRateLimitTier(withApiLogging(async (
|
|
|
209
188
|
UPDATE "api_key"
|
|
210
189
|
SET ${updates.join(", ")}
|
|
211
190
|
WHERE id = $${paramCount} AND "userId" = $${paramCount + 1}
|
|
212
|
-
RETURNING id, "keyPrefix", name, scopes, status, "lastUsedAt", "expiresAt", "createdAt", "updatedAt"
|
|
191
|
+
RETURNING id, "keyPrefix", "keyHash", name, scopes, status, "lastUsedAt", "expiresAt", "createdAt", "updatedAt"
|
|
213
192
|
`;
|
|
214
193
|
|
|
215
194
|
const result = await mutateWithRLS(query, values, authResult.user!.id);
|
|
216
195
|
|
|
217
196
|
if (result.rows.length === 0) {
|
|
218
197
|
const response = createApiError('API key not found', 404, null, 'API_KEY_NOT_FOUND');
|
|
219
|
-
return addCorsHeaders(response);
|
|
198
|
+
return addCorsHeaders(response, req);
|
|
220
199
|
}
|
|
221
200
|
|
|
222
|
-
|
|
223
|
-
|
|
201
|
+
// A status change must take effect immediately: drop the cached validation
|
|
202
|
+
// entry so the next request re-reads the row (see #92). keyHash is only
|
|
203
|
+
// used for the invalidation and never returned to the client.
|
|
204
|
+
const { keyHash, ...updatedApiKey } = result.rows[0] as { keyHash: string } & Record<string, unknown>;
|
|
205
|
+
invalidateApiKeyCache(keyHash);
|
|
206
|
+
|
|
207
|
+
const response = createApiResponse(updatedApiKey);
|
|
208
|
+
return addCorsHeaders(response, req);
|
|
224
209
|
} catch (error) {
|
|
225
210
|
console.error('Error updating API key:', error);
|
|
226
211
|
const response = createApiError('Internal server error', 500);
|
|
227
|
-
return addCorsHeaders(response);
|
|
212
|
+
return addCorsHeaders(response, req);
|
|
228
213
|
}
|
|
229
214
|
}), 'strict');
|
|
230
215
|
|
|
@@ -234,34 +219,23 @@ export const DELETE = withRateLimitTier(withApiLogging(async (
|
|
|
234
219
|
{ params }: { params: Promise<{ id: string }> }
|
|
235
220
|
): Promise<NextResponse> => {
|
|
236
221
|
try {
|
|
237
|
-
// Authenticate using dual auth
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
// Authenticate using dual auth; the API-key scope is declared at the entry
|
|
223
|
+
// point, which fails closed for keys that lack it (#93).
|
|
224
|
+
const authResult = await authenticateRequest(req, { requiredScope: 'admin:api-keys' });
|
|
225
|
+
|
|
240
226
|
if (!authResult.success) {
|
|
241
|
-
return
|
|
242
|
-
{ success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
|
|
243
|
-
{ status: 401 }
|
|
244
|
-
);
|
|
227
|
+
return createAuthFailureResponse(authResult);
|
|
245
228
|
}
|
|
246
229
|
|
|
247
230
|
if (authResult.rateLimitResponse) {
|
|
248
231
|
return authResult.rateLimitResponse as NextResponse;
|
|
249
232
|
}
|
|
250
233
|
|
|
251
|
-
// Check required permissions - session users have admin access, API key users need specific scope
|
|
252
|
-
const hasPermission = authResult.type === 'session' ||
|
|
253
|
-
(authResult.type === 'api-key' && hasRequiredScope(authResult, 'admin:api-keys'));
|
|
254
|
-
|
|
255
|
-
if (!hasPermission) {
|
|
256
|
-
const response = createApiError('Insufficient permissions. Admin access required for API key management.', 403);
|
|
257
|
-
return addCorsHeaders(response);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
234
|
const { id } = await params;
|
|
261
235
|
|
|
262
236
|
if (!id || id.trim() === '') {
|
|
263
237
|
const response = createApiError('API key ID is required', 400, null, 'MISSING_API_KEY_ID');
|
|
264
|
-
return addCorsHeaders(response);
|
|
238
|
+
return addCorsHeaders(response, req);
|
|
265
239
|
}
|
|
266
240
|
|
|
267
241
|
// For API key auth, prevent deletion of the current API key being used
|
|
@@ -272,7 +246,7 @@ export const DELETE = withRateLimitTier(withApiLogging(async (
|
|
|
272
246
|
null,
|
|
273
247
|
'SELF_REVOKE_FORBIDDEN'
|
|
274
248
|
);
|
|
275
|
-
return addCorsHeaders(response);
|
|
249
|
+
return addCorsHeaders(response, req);
|
|
276
250
|
}
|
|
277
251
|
|
|
278
252
|
// Soft delete - just mark as inactive
|
|
@@ -280,25 +254,30 @@ export const DELETE = withRateLimitTier(withApiLogging(async (
|
|
|
280
254
|
`UPDATE "api_key"
|
|
281
255
|
SET status = 'inactive', "updatedAt" = CURRENT_TIMESTAMP
|
|
282
256
|
WHERE id = $1 AND "userId" = $2
|
|
283
|
-
RETURNING id, name`,
|
|
257
|
+
RETURNING id, name, "keyHash"`,
|
|
284
258
|
[id, authResult.user!.id],
|
|
285
259
|
authResult.user!.id
|
|
286
260
|
);
|
|
287
261
|
|
|
288
262
|
if (result.rows.length === 0) {
|
|
289
263
|
const response = createApiError('API key not found', 404, null, 'API_KEY_NOT_FOUND');
|
|
290
|
-
return addCorsHeaders(response);
|
|
264
|
+
return addCorsHeaders(response, req);
|
|
291
265
|
}
|
|
292
266
|
|
|
267
|
+
const revokedRow = result.rows[0] as { name: string; keyHash: string };
|
|
268
|
+
|
|
269
|
+
// Revocation must be effective right away, not after the 5 min cache TTL (see #92)
|
|
270
|
+
invalidateApiKeyCache(revokedRow.keyHash);
|
|
271
|
+
|
|
293
272
|
const response = createApiResponse({
|
|
294
273
|
revoked: true,
|
|
295
274
|
id,
|
|
296
|
-
name:
|
|
275
|
+
name: revokedRow.name
|
|
297
276
|
});
|
|
298
|
-
return addCorsHeaders(response);
|
|
277
|
+
return addCorsHeaders(response, req);
|
|
299
278
|
} catch (error) {
|
|
300
279
|
console.error('Error revoking API key:', error);
|
|
301
280
|
const response = createApiError('Internal server error', 500);
|
|
302
|
-
return addCorsHeaders(response);
|
|
281
|
+
return addCorsHeaders(response, req);
|
|
303
282
|
}
|
|
304
283
|
}), 'strict');
|