@payez/next-mvp 4.0.1 → 4.0.3
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/api/auth-handler.d.ts +66 -0
- package/dist/api/auth-handler.js +397 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.js +19 -0
- package/dist/api-handlers/account/change-password.d.ts +9 -0
- package/dist/api-handlers/account/change-password.js +110 -0
- package/dist/api-handlers/account/masked-info.d.ts +2 -0
- package/dist/api-handlers/account/masked-info.js +41 -0
- package/dist/api-handlers/account/profile.d.ts +3 -0
- package/dist/api-handlers/account/profile.js +63 -0
- package/dist/api-handlers/account/recovery/initiate.d.ts +2 -0
- package/dist/api-handlers/account/recovery/initiate.js +26 -0
- package/dist/api-handlers/account/recovery/send-code.d.ts +2 -0
- package/dist/api-handlers/account/recovery/send-code.js +28 -0
- package/dist/api-handlers/account/recovery/verify-code.d.ts +2 -0
- package/dist/api-handlers/account/recovery/verify-code.js +28 -0
- package/dist/api-handlers/account/reset-password.d.ts +2 -0
- package/dist/api-handlers/account/reset-password.js +26 -0
- package/dist/api-handlers/account/send-code.d.ts +24 -0
- package/dist/api-handlers/account/send-code.js +60 -0
- package/dist/api-handlers/account/update-phone.d.ts +27 -0
- package/dist/api-handlers/account/update-phone.js +64 -0
- package/dist/api-handlers/account/validate-password.d.ts +17 -0
- package/dist/api-handlers/account/validate-password.js +81 -0
- package/dist/api-handlers/account/verify-email.d.ts +26 -0
- package/dist/api-handlers/account/verify-email.js +106 -0
- package/dist/api-handlers/account/verify-sms.d.ts +26 -0
- package/dist/api-handlers/account/verify-sms.js +106 -0
- package/dist/api-handlers/admin/analytics.d.ts +19 -0
- package/dist/api-handlers/admin/analytics.js +378 -0
- package/dist/api-handlers/admin/audit.d.ts +19 -0
- package/dist/api-handlers/admin/audit.js +213 -0
- package/dist/api-handlers/admin/index.d.ts +21 -0
- package/dist/api-handlers/admin/index.js +42 -0
- package/dist/api-handlers/admin/redis-sessions.d.ts +35 -0
- package/dist/api-handlers/admin/redis-sessions.js +203 -0
- package/dist/api-handlers/admin/sessions.d.ts +20 -0
- package/dist/api-handlers/admin/sessions.js +283 -0
- package/dist/api-handlers/admin/site-logs.d.ts +45 -0
- package/dist/api-handlers/admin/site-logs.js +317 -0
- package/dist/api-handlers/admin/stats.d.ts +20 -0
- package/dist/api-handlers/admin/stats.js +239 -0
- package/dist/api-handlers/admin/users.d.ts +19 -0
- package/dist/api-handlers/admin/users.js +221 -0
- package/dist/api-handlers/admin/vibe-data.d.ts +79 -0
- package/dist/api-handlers/admin/vibe-data.js +267 -0
- package/dist/api-handlers/anon/preferences.d.ts +37 -0
- package/dist/api-handlers/anon/preferences.js +96 -0
- package/dist/api-handlers/auth/jwks.d.ts +2 -0
- package/dist/api-handlers/auth/jwks.js +24 -0
- package/dist/api-handlers/auth/login.d.ts +42 -0
- package/dist/api-handlers/auth/login.js +178 -0
- package/dist/api-handlers/auth/refresh.d.ts +74 -0
- package/dist/api-handlers/auth/refresh.js +633 -0
- package/dist/api-handlers/auth/signout.d.ts +37 -0
- package/dist/api-handlers/auth/signout.js +186 -0
- package/dist/api-handlers/auth/status.d.ts +8 -0
- package/dist/api-handlers/auth/status.js +23 -0
- package/dist/api-handlers/auth/update-session.d.ts +37 -0
- package/dist/api-handlers/auth/update-session.js +93 -0
- package/dist/api-handlers/auth/validate.d.ts +6 -0
- package/dist/api-handlers/auth/validate.js +43 -0
- package/dist/api-handlers/auth/verify-code.d.ts +43 -0
- package/dist/api-handlers/auth/verify-code.js +90 -0
- package/dist/api-handlers/session/refresh-viability.d.ts +14 -0
- package/dist/api-handlers/session/refresh-viability.js +39 -0
- package/dist/api-handlers/session/viability.d.ts +13 -0
- package/dist/api-handlers/session/viability.js +114 -0
- package/dist/api-handlers/test/force-expire.d.ts +23 -0
- package/dist/api-handlers/test/force-expire.js +59 -0
- package/dist/auth/auth-decision.d.ts +39 -0
- package/dist/auth/auth-decision.js +182 -0
- package/dist/auth/better-auth.d.ts +79 -0
- package/dist/auth/better-auth.js +119 -0
- package/dist/auth/route-config.d.ts +66 -0
- package/dist/auth/route-config.js +190 -0
- package/dist/auth/types/auth-types.d.ts +417 -0
- package/dist/auth/types/auth-types.js +53 -0
- package/dist/auth/types/index.d.ts +6 -0
- package/dist/auth/types/index.js +22 -0
- package/dist/auth/unauthenticated-routes.d.ts +1 -0
- package/dist/auth/unauthenticated-routes.js +19 -0
- package/dist/auth/utils/idp-client.d.ts +94 -0
- package/dist/auth/utils/idp-client.js +384 -0
- package/dist/auth/utils/index.d.ts +5 -0
- package/dist/auth/utils/index.js +21 -0
- package/dist/auth/utils/token-utils.d.ts +83 -0
- package/dist/auth/utils/token-utils.js +218 -0
- package/dist/client/AuthContext.d.ts +19 -0
- package/dist/client/AuthContext.js +115 -0
- package/dist/client/better-auth-client.d.ts +1020 -0
- package/dist/client/better-auth-client.js +68 -0
- package/dist/client/fetch-with-auth.d.ts +11 -0
- package/dist/client/fetch-with-auth.js +44 -0
- package/dist/client/fetchWithSession.d.ts +3 -0
- package/dist/client/fetchWithSession.js +24 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +20 -0
- package/dist/client/useAnonSession.d.ts +36 -0
- package/dist/client/useAnonSession.js +99 -0
- package/dist/components/SessionSync.d.ts +13 -0
- package/dist/components/SessionSync.js +121 -0
- package/dist/components/SignalRHealthCheck.d.ts +10 -0
- package/dist/components/SignalRHealthCheck.js +97 -0
- package/dist/components/account/MobileNavDrawer.d.ts +32 -0
- package/dist/components/account/MobileNavDrawer.js +81 -0
- package/dist/components/account/UserAvatarMenu.d.ts +20 -0
- package/dist/components/account/UserAvatarMenu.js +91 -0
- package/dist/components/account/index.d.ts +9 -0
- package/dist/components/account/index.js +13 -0
- package/dist/components/admin/AlertSettingsTab.d.ts +48 -0
- package/dist/components/admin/AlertSettingsTab.js +351 -0
- package/dist/components/admin/AnalyticsTab.d.ts +22 -0
- package/dist/components/admin/AnalyticsTab.js +167 -0
- package/dist/components/admin/DataBrowserTab.d.ts +19 -0
- package/dist/components/admin/DataBrowserTab.js +252 -0
- package/dist/components/admin/LoggingSettingsTab.d.ts +73 -0
- package/dist/components/admin/LoggingSettingsTab.js +339 -0
- package/dist/components/admin/SessionsTab.d.ts +37 -0
- package/dist/components/admin/SessionsTab.js +165 -0
- package/dist/components/admin/StatsTab.d.ts +53 -0
- package/dist/components/admin/StatsTab.js +161 -0
- package/dist/components/admin/VibeAdminContext.d.ts +32 -0
- package/dist/components/admin/VibeAdminContext.js +38 -0
- package/dist/components/admin/VibeAdminLayout.d.ts +11 -0
- package/dist/components/admin/VibeAdminLayout.js +71 -0
- package/dist/components/admin/index.d.ts +29 -0
- package/dist/components/admin/index.js +44 -0
- package/dist/components/auth/FederatedAuthSection.d.ts +8 -0
- package/dist/components/auth/FederatedAuthSection.js +45 -0
- package/dist/components/auth/ModeAwareLoginPage.d.ts +10 -0
- package/dist/components/auth/ModeAwareLoginPage.js +42 -0
- package/dist/components/auth/ModeAwareSignupPage.d.ts +9 -0
- package/dist/components/auth/ModeAwareSignupPage.js +78 -0
- package/dist/components/auth/TraditionalAuthSection.d.ts +14 -0
- package/dist/components/auth/TraditionalAuthSection.js +20 -0
- package/dist/components/recovery/CompleteStep.d.ts +5 -0
- package/dist/components/recovery/CompleteStep.js +8 -0
- package/dist/components/recovery/InitiateRecoveryStep.d.ts +8 -0
- package/dist/components/recovery/InitiateRecoveryStep.js +20 -0
- package/dist/components/recovery/SelectMethodStep.d.ts +8 -0
- package/dist/components/recovery/SelectMethodStep.js +8 -0
- package/dist/components/recovery/SetPasswordStep.d.ts +6 -0
- package/dist/components/recovery/SetPasswordStep.js +20 -0
- package/dist/components/recovery/VerifyCodeStep.d.ts +10 -0
- package/dist/components/recovery/VerifyCodeStep.js +24 -0
- package/dist/components/reserved/ReservedRecoveryWarning.d.ts +38 -0
- package/dist/components/reserved/ReservedRecoveryWarning.js +92 -0
- package/dist/components/reserved/ReservedStatusBox.d.ts +30 -0
- package/dist/components/reserved/ReservedStatusBox.js +71 -0
- package/dist/components/ui/BetaBadge.d.ts +29 -0
- package/dist/components/ui/BetaBadge.js +38 -0
- package/dist/components/ui/Footer.d.ts +37 -0
- package/dist/components/ui/Footer.js +41 -0
- package/dist/config/env.d.ts +66 -0
- package/dist/config/env.js +57 -0
- package/dist/config/logger.d.ts +57 -0
- package/dist/config/logger.js +73 -0
- package/dist/config/logging-config.d.ts +30 -0
- package/dist/config/logging-config.js +122 -0
- package/dist/config/unauthenticated-routes.d.ts +17 -0
- package/dist/config/unauthenticated-routes.js +24 -0
- package/dist/config/vibe-log-transport.d.ts +81 -0
- package/dist/config/vibe-log-transport.js +212 -0
- package/dist/edge/internal-api-url.d.ts +53 -0
- package/dist/edge/internal-api-url.js +63 -0
- package/dist/edge/middleware.d.ts +14 -0
- package/dist/edge/middleware.js +32 -0
- package/dist/hooks/useAuth.d.ts +23 -0
- package/dist/hooks/useAuth.js +83 -0
- package/dist/hooks/useAuthSettings.d.ts +59 -0
- package/dist/hooks/useAuthSettings.js +93 -0
- package/dist/hooks/useAvailableProviders.d.ts +43 -0
- package/dist/hooks/useAvailableProviders.js +112 -0
- package/dist/hooks/usePasswordValidation.d.ts +27 -0
- package/dist/hooks/usePasswordValidation.js +102 -0
- package/dist/hooks/useProfile.d.ts +15 -0
- package/dist/hooks/useProfile.js +59 -0
- package/dist/hooks/usePublicAuthSettings.d.ts +56 -0
- package/dist/hooks/usePublicAuthSettings.js +131 -0
- package/dist/hooks/useSessionExpiration.d.ts +56 -0
- package/dist/hooks/useSessionExpiration.js +72 -0
- package/dist/hooks/useViabilitySession.d.ts +75 -0
- package/dist/hooks/useViabilitySession.js +269 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +53 -0
- package/dist/lib/anon-session.d.ts +74 -0
- package/dist/lib/anon-session.js +169 -0
- package/dist/lib/api-handler.d.ts +123 -0
- package/dist/lib/api-handler.js +478 -0
- package/dist/lib/app-slug.d.ts +95 -0
- package/dist/lib/app-slug.js +172 -0
- package/dist/lib/demo-mode.d.ts +6 -0
- package/dist/lib/demo-mode.js +16 -0
- package/dist/lib/geolocation.d.ts +64 -0
- package/dist/lib/geolocation.js +235 -0
- package/dist/lib/idp-client-config.d.ts +75 -0
- package/dist/lib/idp-client-config.js +425 -0
- package/dist/lib/idp-fetch.d.ts +14 -0
- package/dist/lib/idp-fetch.js +91 -0
- package/dist/lib/internal-api.d.ts +87 -0
- package/dist/lib/internal-api.js +122 -0
- package/dist/lib/jwt-decode-client.d.ts +10 -0
- package/dist/lib/jwt-decode-client.js +46 -0
- package/dist/lib/jwt-decode.d.ts +48 -0
- package/dist/lib/jwt-decode.js +57 -0
- package/dist/lib/rate-limit-service.d.ts +23 -0
- package/dist/lib/rate-limit-service.js +6 -0
- package/dist/lib/redis.d.ts +5 -0
- package/dist/lib/redis.js +28 -0
- package/dist/lib/refresh-token-validator.d.ts +13 -0
- package/dist/lib/refresh-token-validator.js +117 -0
- package/dist/lib/roles.d.ts +145 -0
- package/dist/lib/roles.js +168 -0
- package/dist/lib/secret-validation.d.ts +4 -0
- package/dist/lib/secret-validation.js +14 -0
- package/dist/lib/session-store.d.ts +170 -0
- package/dist/lib/session-store.js +545 -0
- package/dist/lib/session.d.ts +21 -0
- package/dist/lib/session.js +26 -0
- package/dist/lib/site-logger.d.ts +214 -0
- package/dist/lib/site-logger.js +210 -0
- package/dist/lib/standardized-client-api.d.ts +161 -0
- package/dist/lib/standardized-client-api.js +791 -0
- package/dist/lib/startup-init.d.ts +40 -0
- package/dist/lib/startup-init.js +257 -0
- package/dist/lib/test-aware-get-token.d.ts +2 -0
- package/dist/lib/test-aware-get-token.js +86 -0
- package/dist/lib/token-expiry.d.ts +14 -0
- package/dist/lib/token-expiry.js +39 -0
- package/dist/lib/token-lifecycle.d.ts +78 -0
- package/dist/lib/token-lifecycle.js +360 -0
- package/dist/lib/types/api-responses.d.ts +128 -0
- package/dist/lib/types/api-responses.js +171 -0
- package/dist/lib/user-agent-parser.d.ts +50 -0
- package/dist/lib/user-agent-parser.js +220 -0
- package/dist/logging/api/admin-analytics.d.ts +3 -0
- package/dist/logging/api/admin-analytics.js +45 -0
- package/dist/logging/api/audit-log.d.ts +3 -0
- package/dist/logging/api/audit-log.js +52 -0
- package/dist/logging/components/AdminAnalyticsLayout.d.ts +10 -0
- package/dist/logging/components/AdminAnalyticsLayout.js +11 -0
- package/dist/logging/components/AuditLogViewer.d.ts +7 -0
- package/dist/logging/components/AuditLogViewer.js +51 -0
- package/dist/logging/components/ErrorMetricsCard.d.ts +7 -0
- package/dist/logging/components/ErrorMetricsCard.js +16 -0
- package/dist/logging/components/HealthMetricsCard.d.ts +7 -0
- package/dist/logging/components/HealthMetricsCard.js +19 -0
- package/dist/logging/hooks/useAdminAnalytics.d.ts +24 -0
- package/dist/logging/hooks/useAdminAnalytics.js +22 -0
- package/dist/logging/hooks/useAuditLog.d.ts +6 -0
- package/dist/logging/hooks/useAuditLog.js +25 -0
- package/dist/logging/hooks/useErrorMetrics.d.ts +6 -0
- package/dist/logging/hooks/useErrorMetrics.js +38 -0
- package/dist/logging/hooks/useHealthMetrics.d.ts +6 -0
- package/dist/logging/hooks/useHealthMetrics.js +41 -0
- package/dist/logging/index.d.ts +11 -0
- package/dist/logging/index.js +40 -0
- package/dist/logging/types/analytics.d.ts +68 -0
- package/dist/logging/types/analytics.js +3 -0
- package/dist/logging/types/audit.d.ts +29 -0
- package/dist/logging/types/audit.js +2 -0
- package/dist/logging/types/index.d.ts +2 -0
- package/dist/logging/types/index.js +19 -0
- package/dist/middleware/auth-decision.d.ts +33 -0
- package/dist/middleware/auth-decision.js +65 -0
- package/dist/middleware/create-middleware.d.ts +102 -0
- package/dist/middleware/create-middleware.js +469 -0
- package/dist/middleware/rbac-check.d.ts +51 -0
- package/dist/middleware/rbac-check.js +219 -0
- package/dist/middleware/twofa-presets.d.ts +134 -0
- package/dist/middleware/twofa-presets.js +175 -0
- package/dist/models/DecodedAccessToken.d.ts +17 -0
- package/dist/models/DecodedAccessToken.js +2 -0
- package/dist/models/SessionModel.d.ts +122 -0
- package/dist/models/SessionModel.js +136 -0
- package/dist/pages/admin-login/page.d.ts +31 -0
- package/dist/pages/admin-login/page.js +73 -0
- package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.d.ts +18 -0
- package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.js +276 -0
- package/dist/pages/admin-page-permissions/index.d.ts +6 -0
- package/dist/pages/admin-page-permissions/index.js +13 -0
- package/dist/pages/admin-roles/RolesAdminPage.d.ts +16 -0
- package/dist/pages/admin-roles/RolesAdminPage.js +261 -0
- package/dist/pages/admin-roles/index.d.ts +8 -0
- package/dist/pages/admin-roles/index.js +15 -0
- package/dist/pages/admin-roles/modals.d.ts +72 -0
- package/dist/pages/admin-roles/modals.js +154 -0
- package/dist/pages/client-admin/ClientSiteAdminPage.d.ts +79 -0
- package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -0
- package/dist/pages/client-admin/index.d.ts +32 -0
- package/dist/pages/client-admin/index.js +37 -0
- package/dist/pages/coming-soon/page.d.ts +8 -0
- package/dist/pages/coming-soon/page.js +28 -0
- package/dist/pages/login/page.d.ts +22 -0
- package/dist/pages/login/page.js +230 -0
- package/dist/pages/profile/EnhancedProfilePage.d.ts +13 -0
- package/dist/pages/profile/EnhancedProfilePage.js +150 -0
- package/dist/pages/profile/index.d.ts +8 -0
- package/dist/pages/profile/index.js +16 -0
- package/dist/pages/profile/page.d.ts +19 -0
- package/dist/pages/profile/page.js +47 -0
- package/dist/pages/recovery/page.d.ts +1 -0
- package/dist/pages/recovery/page.js +142 -0
- package/dist/pages/roles/MyRolesPage.d.ts +24 -0
- package/dist/pages/roles/MyRolesPage.js +71 -0
- package/dist/pages/roles/components.d.ts +63 -0
- package/dist/pages/roles/components.js +108 -0
- package/dist/pages/roles/index.d.ts +8 -0
- package/dist/pages/roles/index.js +19 -0
- package/dist/pages/security/EnhancedSecurityPage.d.ts +14 -0
- package/dist/pages/security/EnhancedSecurityPage.js +248 -0
- package/dist/pages/security/index.d.ts +8 -0
- package/dist/pages/security/index.js +16 -0
- package/dist/pages/security/page.d.ts +21 -0
- package/dist/pages/security/page.js +212 -0
- package/dist/pages/settings/EnhancedSettingsPage.d.ts +46 -0
- package/dist/pages/settings/EnhancedSettingsPage.js +231 -0
- package/dist/pages/settings/index.d.ts +8 -0
- package/dist/pages/settings/index.js +16 -0
- package/dist/pages/settings/page.d.ts +7 -0
- package/dist/pages/settings/page.js +26 -0
- package/dist/pages/showcase/ShowcasePage.d.ts +13 -0
- package/dist/pages/showcase/ShowcasePage.js +142 -0
- package/dist/pages/showcase/index.d.ts +12 -0
- package/dist/pages/showcase/index.js +17 -0
- package/dist/pages/test-env/EmergencyLogoutPage.d.ts +14 -0
- package/dist/pages/test-env/EmergencyLogoutPage.js +99 -0
- package/dist/pages/test-env/JwtInspectPage.d.ts +14 -0
- package/dist/pages/test-env/JwtInspectPage.js +116 -0
- package/dist/pages/test-env/RefreshTokenPage.d.ts +15 -0
- package/dist/pages/test-env/RefreshTokenPage.js +93 -0
- package/dist/pages/test-env/TestEnvPage.d.ts +13 -0
- package/dist/pages/test-env/TestEnvPage.js +51 -0
- package/dist/pages/test-env/index.d.ts +24 -0
- package/dist/pages/test-env/index.js +32 -0
- package/dist/pages/verify-code/page.d.ts +30 -0
- package/dist/pages/verify-code/page.js +412 -0
- package/dist/routes/account/index.d.ts +28 -0
- package/dist/routes/account/index.js +71 -0
- package/dist/routes/account/masked-info.d.ts +33 -0
- package/dist/routes/account/masked-info.js +39 -0
- package/dist/routes/account/send-code.d.ts +37 -0
- package/dist/routes/account/send-code.js +42 -0
- package/dist/routes/account/update-phone.d.ts +13 -0
- package/dist/routes/account/update-phone.js +17 -0
- package/dist/routes/account/verify-email.d.ts +38 -0
- package/dist/routes/account/verify-email.js +43 -0
- package/dist/routes/account/verify-sms.d.ts +38 -0
- package/dist/routes/account/verify-sms.js +43 -0
- package/dist/routes/auth/index.d.ts +19 -0
- package/dist/routes/auth/index.js +64 -0
- package/dist/routes/auth/logout.d.ts +31 -0
- package/dist/routes/auth/logout.js +98 -0
- package/dist/routes/auth/nextauth.d.ts +22 -0
- package/dist/routes/auth/nextauth.js +40 -0
- package/dist/routes/auth/refresh.d.ts +30 -0
- package/dist/routes/auth/refresh.js +51 -0
- package/dist/routes/auth/session.d.ts +43 -0
- package/dist/routes/auth/session.js +157 -0
- package/dist/routes/auth/settings.d.ts +25 -0
- package/dist/routes/auth/settings.js +55 -0
- package/dist/routes/auth/viability.d.ts +52 -0
- package/dist/routes/auth/viability.js +190 -0
- package/dist/routes/index.d.ts +12 -0
- package/dist/routes/index.js +54 -0
- package/dist/routes/session/index.d.ts +6 -0
- package/dist/routes/session/index.js +10 -0
- package/dist/routes/session/refresh-viability.d.ts +16 -0
- package/dist/routes/session/refresh-viability.js +20 -0
- package/dist/server/auth-guard.d.ts +46 -0
- package/dist/server/auth-guard.js +128 -0
- package/dist/server/auth.d.ts +50 -0
- package/dist/server/auth.js +62 -0
- package/dist/server/decode-session.d.ts +30 -0
- package/dist/server/decode-session.js +78 -0
- package/dist/server/slim-middleware.d.ts +23 -0
- package/dist/server/slim-middleware.js +89 -0
- package/dist/server/with-auth.d.ts +33 -0
- package/dist/server/with-auth.js +59 -0
- package/dist/services/signalrActivityService.d.ts +44 -0
- package/dist/services/signalrActivityService.js +257 -0
- package/dist/stores/authStore.d.ts +154 -0
- package/dist/stores/authStore.js +1527 -0
- package/dist/theme/ThemeProvider.d.ts +14 -0
- package/dist/theme/ThemeProvider.js +28 -0
- package/dist/theme/default.d.ts +8 -0
- package/dist/theme/default.js +33 -0
- package/dist/theme/index.d.ts +15 -0
- package/dist/theme/index.js +25 -0
- package/dist/theme/types.d.ts +56 -0
- package/dist/theme/types.js +8 -0
- package/dist/theme/useTheme.d.ts +60 -0
- package/dist/theme/useTheme.js +63 -0
- package/dist/theme/utils.d.ts +13 -0
- package/dist/theme/utils.js +39 -0
- package/dist/types/api.d.ts +134 -0
- package/dist/types/api.js +44 -0
- package/dist/types/auth.d.ts +19 -0
- package/dist/types/auth.js +2 -0
- package/dist/types/logging.d.ts +42 -0
- package/dist/types/logging.js +2 -0
- package/dist/types/recovery.d.ts +48 -0
- package/dist/types/recovery.js +2 -0
- package/dist/types/security.d.ts +1 -0
- package/dist/types/security.js +2 -0
- package/dist/utils/api.d.ts +85 -0
- package/dist/utils/api.js +287 -0
- package/dist/utils/circuitBreaker.d.ts +43 -0
- package/dist/utils/circuitBreaker.js +91 -0
- package/dist/utils/error-message.d.ts +1 -0
- package/dist/utils/error-message.js +103 -0
- package/dist/utils/layout/reservedSpace.d.ts +59 -0
- package/dist/utils/layout/reservedSpace.js +102 -0
- package/dist/utils/logout.d.ts +14 -0
- package/dist/utils/logout.js +32 -0
- package/dist/vibe/client.d.ts +261 -0
- package/dist/vibe/client.js +445 -0
- package/dist/vibe/enterprise-auth.d.ts +106 -0
- package/dist/vibe/enterprise-auth.js +173 -0
- package/dist/vibe/errors.d.ts +83 -0
- package/dist/vibe/errors.js +146 -0
- package/dist/vibe/generic.d.ts +234 -0
- package/dist/vibe/generic.js +369 -0
- package/dist/vibe/hooks/index.d.ts +169 -0
- package/dist/vibe/hooks/index.js +252 -0
- package/dist/vibe/index.d.ts +25 -0
- package/dist/vibe/index.js +72 -0
- package/dist/vibe/sessions.d.ts +161 -0
- package/dist/vibe/sessions.js +391 -0
- package/dist/vibe/types.d.ts +353 -0
- package/dist/vibe/types.js +315 -0
- package/package.json +1 -1
- package/src/auth/better-auth.ts +2 -2
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Admin Vibe Data API Handler
|
|
4
|
+
*
|
|
5
|
+
* Provides admin-level access to Vibe data using service account credentials.
|
|
6
|
+
* Bypasses user-level filtering to allow admins to view all records.
|
|
7
|
+
*
|
|
8
|
+
* @version 1.0
|
|
9
|
+
* @requires Admin role (vibe_app_admin or payez_admin)
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.createGetCollectionsHandler = createGetCollectionsHandler;
|
|
46
|
+
exports.createGetTablesHandler = createGetTablesHandler;
|
|
47
|
+
exports.createGetTableDataHandler = createGetTableDataHandler;
|
|
48
|
+
exports.createGetRecordHandler = createGetRecordHandler;
|
|
49
|
+
exports.createUpdateRecordHandler = createUpdateRecordHandler;
|
|
50
|
+
exports.createDeleteRecordHandler = createDeleteRecordHandler;
|
|
51
|
+
exports.createQueryHandler = createQueryHandler;
|
|
52
|
+
const server_1 = require("next/server");
|
|
53
|
+
const auth_1 = require("../../server/auth");
|
|
54
|
+
const startup_init_1 = require("../../lib/startup-init");
|
|
55
|
+
const roles_1 = require("../../lib/roles");
|
|
56
|
+
/**
|
|
57
|
+
* Check if the current user has admin role
|
|
58
|
+
*/
|
|
59
|
+
async function checkAdminRole(request) {
|
|
60
|
+
const session = await (0, auth_1.getSession)(request);
|
|
61
|
+
if (!session?.user) {
|
|
62
|
+
return {
|
|
63
|
+
isAdmin: false,
|
|
64
|
+
error: server_1.NextResponse.json({ success: false, error: { code: 'UNAUTHORIZED', message: 'Please sign in' } }, { status: 401 }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const userRoles = session.user?.roles || [];
|
|
68
|
+
const hasAdminRole = roles_1.ADMIN_ROLES.some(role => userRoles.includes(role));
|
|
69
|
+
if (!hasAdminRole) {
|
|
70
|
+
return {
|
|
71
|
+
isAdmin: false,
|
|
72
|
+
error: server_1.NextResponse.json({ success: false, error: { code: 'FORBIDDEN', message: 'Admin access required' } }, { status: 403 }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { isAdmin: true };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Make a service account request to Vibe (admin mode - no user filtering)
|
|
79
|
+
*/
|
|
80
|
+
async function vibeServiceRequest(endpoint, options) {
|
|
81
|
+
const idpUrl = process.env.NEXT_PUBLIC_IDP_URL || process.env.IDP_URL;
|
|
82
|
+
const clientId = process.env.VIBE_CLIENT_ID;
|
|
83
|
+
const signingKey = process.env.VIBE_HMAC_KEY;
|
|
84
|
+
if (!idpUrl || !clientId || !signingKey) {
|
|
85
|
+
console.error('[Admin Vibe] Missing config:', { idpUrl: !!idpUrl, clientId: !!clientId, signingKey: !!signingKey });
|
|
86
|
+
return { ok: false, status: 500, data: null, error: 'Vibe not configured' };
|
|
87
|
+
}
|
|
88
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
89
|
+
const stringToSign = `${timestamp}|${options.method}|${endpoint}`;
|
|
90
|
+
// Generate HMAC signature
|
|
91
|
+
const crypto = await Promise.resolve().then(() => __importStar(require('crypto')));
|
|
92
|
+
const signature = crypto
|
|
93
|
+
.createHmac('sha256', Buffer.from(signingKey, 'base64'))
|
|
94
|
+
.update(stringToSign)
|
|
95
|
+
.digest('base64');
|
|
96
|
+
const proxyUrl = `${idpUrl}/api/vibe/proxy`;
|
|
97
|
+
// Get the client slug from startup config for multi-client admin support
|
|
98
|
+
const idpConfig = (0, startup_init_1.getStartupIDPConfig)();
|
|
99
|
+
const idpClientId = idpConfig?.clientSlug || idpConfig?.clientId;
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch(proxyUrl, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: {
|
|
104
|
+
'Content-Type': 'application/json',
|
|
105
|
+
'X-Vibe-Client-Id': clientId,
|
|
106
|
+
'X-Vibe-Timestamp': String(timestamp),
|
|
107
|
+
'X-Vibe-Signature': signature,
|
|
108
|
+
// For multi-client admins: specify which client context to use
|
|
109
|
+
...(idpClientId && { 'X-Client-Id': idpClientId }),
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
endpoint,
|
|
113
|
+
method: options.method,
|
|
114
|
+
data: options.body ?? null,
|
|
115
|
+
}),
|
|
116
|
+
cache: 'no-store',
|
|
117
|
+
});
|
|
118
|
+
if (res.status === 204) {
|
|
119
|
+
return { ok: true, status: 204, data: null };
|
|
120
|
+
}
|
|
121
|
+
if (!res.ok) {
|
|
122
|
+
const errorText = await res.text();
|
|
123
|
+
console.error(`[Admin Vibe] Request failed: ${options.method} ${endpoint} - ${res.status}`, errorText);
|
|
124
|
+
return { ok: false, status: res.status, data: null, error: errorText };
|
|
125
|
+
}
|
|
126
|
+
const body = await res.json();
|
|
127
|
+
return { ok: true, status: res.status, data: body };
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error(`[Admin Vibe] Request exception: ${options.method} ${endpoint}`, error);
|
|
131
|
+
return { ok: false, status: 0, data: null, error: String(error) };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* GET /api/admin/vibe/collections
|
|
136
|
+
* List all Vibe collections
|
|
137
|
+
*/
|
|
138
|
+
function createGetCollectionsHandler(config) {
|
|
139
|
+
return async function GET(request) {
|
|
140
|
+
const adminCheck = await checkAdminRole(request);
|
|
141
|
+
if (adminCheck.error)
|
|
142
|
+
return adminCheck.error;
|
|
143
|
+
const result = await vibeServiceRequest('/v1/collections', { method: 'GET' });
|
|
144
|
+
if (!result.ok) {
|
|
145
|
+
return server_1.NextResponse.json({ success: false, error: { code: 'FETCH_ERROR', message: result.error } }, { status: result.status || 500 });
|
|
146
|
+
}
|
|
147
|
+
return server_1.NextResponse.json(result.data);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* GET /api/admin/vibe/collections/[collection]/tables
|
|
152
|
+
* List tables in a collection
|
|
153
|
+
*/
|
|
154
|
+
function createGetTablesHandler(config) {
|
|
155
|
+
return async function GET(request, { params }) {
|
|
156
|
+
const { collection } = await params;
|
|
157
|
+
const adminCheck = await checkAdminRole(request);
|
|
158
|
+
if (adminCheck.error)
|
|
159
|
+
return adminCheck.error;
|
|
160
|
+
const result = await vibeServiceRequest(`/v1/collections/${collection}/tables`, { method: 'GET' });
|
|
161
|
+
if (!result.ok) {
|
|
162
|
+
return server_1.NextResponse.json({ success: false, error: { code: 'FETCH_ERROR', message: result.error } }, { status: result.status || 500 });
|
|
163
|
+
}
|
|
164
|
+
return server_1.NextResponse.json(result.data);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* GET /api/admin/vibe/data/[collection]/[table]
|
|
169
|
+
* Fetch all records from a table (admin - no user filtering)
|
|
170
|
+
*/
|
|
171
|
+
function createGetTableDataHandler(config) {
|
|
172
|
+
return async function GET(request, { params }) {
|
|
173
|
+
const { collection, table } = await params;
|
|
174
|
+
const adminCheck = await checkAdminRole(request);
|
|
175
|
+
if (adminCheck.error)
|
|
176
|
+
return adminCheck.error;
|
|
177
|
+
const searchParams = request.nextUrl.searchParams.toString();
|
|
178
|
+
const queryString = searchParams ? `?${searchParams}` : '';
|
|
179
|
+
const endpoint = `/v1/collections/${collection}/tables/${table}${queryString}`;
|
|
180
|
+
const result = await vibeServiceRequest(endpoint, { method: 'GET' });
|
|
181
|
+
if (result.status === 204) {
|
|
182
|
+
return server_1.NextResponse.json({ data: [], meta: { total: 0, limit: 50, offset: 0 } });
|
|
183
|
+
}
|
|
184
|
+
if (!result.ok) {
|
|
185
|
+
return server_1.NextResponse.json({ success: false, error: { code: 'FETCH_ERROR', message: result.error } }, { status: result.status || 500 });
|
|
186
|
+
}
|
|
187
|
+
return server_1.NextResponse.json(result.data);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* GET /api/admin/vibe/data/[collection]/[table]/[id]
|
|
192
|
+
* Fetch single record (admin access)
|
|
193
|
+
*/
|
|
194
|
+
function createGetRecordHandler(config) {
|
|
195
|
+
return async function GET(request, { params }) {
|
|
196
|
+
const { collection, table, id } = await params;
|
|
197
|
+
const adminCheck = await checkAdminRole(request);
|
|
198
|
+
if (adminCheck.error)
|
|
199
|
+
return adminCheck.error;
|
|
200
|
+
const endpoint = `/v1/collections/${collection}/tables/${table}/${id}`;
|
|
201
|
+
const result = await vibeServiceRequest(endpoint, { method: 'GET' });
|
|
202
|
+
if (!result.ok) {
|
|
203
|
+
const status = result.status === 404 ? 404 : result.status || 500;
|
|
204
|
+
return server_1.NextResponse.json({ success: false, error: { code: result.status === 404 ? 'NOT_FOUND' : 'FETCH_ERROR', message: result.error } }, { status });
|
|
205
|
+
}
|
|
206
|
+
return server_1.NextResponse.json(result.data);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* PUT /api/admin/vibe/data/[collection]/[table]/[id]
|
|
211
|
+
* Update record (admin access)
|
|
212
|
+
*/
|
|
213
|
+
function createUpdateRecordHandler(config) {
|
|
214
|
+
return async function PUT(request, { params }) {
|
|
215
|
+
const { collection, table, id } = await params;
|
|
216
|
+
const adminCheck = await checkAdminRole(request);
|
|
217
|
+
if (adminCheck.error)
|
|
218
|
+
return adminCheck.error;
|
|
219
|
+
const body = await request.json();
|
|
220
|
+
const endpoint = `/v1/collections/${collection}/tables/${table}/${id}`;
|
|
221
|
+
const result = await vibeServiceRequest(endpoint, { method: 'PUT', body });
|
|
222
|
+
if (!result.ok) {
|
|
223
|
+
return server_1.NextResponse.json({ success: false, error: { code: 'UPDATE_ERROR', message: result.error } }, { status: result.status || 500 });
|
|
224
|
+
}
|
|
225
|
+
return server_1.NextResponse.json(result.data);
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* DELETE /api/admin/vibe/data/[collection]/[table]/[id]
|
|
230
|
+
* Delete record (admin access)
|
|
231
|
+
*/
|
|
232
|
+
function createDeleteRecordHandler(config) {
|
|
233
|
+
return async function DELETE(request, { params }) {
|
|
234
|
+
const { collection, table, id } = await params;
|
|
235
|
+
const adminCheck = await checkAdminRole(request);
|
|
236
|
+
if (adminCheck.error)
|
|
237
|
+
return adminCheck.error;
|
|
238
|
+
const endpoint = `/v1/collections/${collection}/tables/${table}/${id}`;
|
|
239
|
+
const result = await vibeServiceRequest(endpoint, { method: 'DELETE' });
|
|
240
|
+
if (!result.ok) {
|
|
241
|
+
return server_1.NextResponse.json({ success: false, error: { code: 'DELETE_ERROR', message: result.error } }, { status: result.status || 500 });
|
|
242
|
+
}
|
|
243
|
+
return new server_1.NextResponse(null, { status: 204 });
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* POST /api/admin/vibe/data/[collection]/[table]/query
|
|
248
|
+
* Query records with filters (admin access)
|
|
249
|
+
*/
|
|
250
|
+
function createQueryHandler(config) {
|
|
251
|
+
return async function POST(request, { params }) {
|
|
252
|
+
const { collection, table } = await params;
|
|
253
|
+
const adminCheck = await checkAdminRole(request);
|
|
254
|
+
if (adminCheck.error)
|
|
255
|
+
return adminCheck.error;
|
|
256
|
+
const body = await request.json();
|
|
257
|
+
const endpoint = `/v1/collections/${collection}/tables/${table}/query`;
|
|
258
|
+
const result = await vibeServiceRequest(endpoint, { method: 'POST', body });
|
|
259
|
+
if (result.status === 204) {
|
|
260
|
+
return server_1.NextResponse.json({ data: [], meta: { total: 0, page: 1, pageSize: 20 } });
|
|
261
|
+
}
|
|
262
|
+
if (!result.ok) {
|
|
263
|
+
return server_1.NextResponse.json({ success: false, error: { code: 'QUERY_ERROR', message: result.error } }, { status: result.status || 500 });
|
|
264
|
+
}
|
|
265
|
+
return server_1.NextResponse.json(result.data);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anonymous Session Preferences API Handler
|
|
3
|
+
*
|
|
4
|
+
* GET /api/anon/preferences - Get current preferences
|
|
5
|
+
* POST /api/anon/preferences - Update preferences
|
|
6
|
+
*
|
|
7
|
+
* Sets a cookie to track anonymous visitors and stores preferences in Redis.
|
|
8
|
+
*/
|
|
9
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
10
|
+
import { AnonSessionPreferences } from '../../lib/anon-session';
|
|
11
|
+
/**
|
|
12
|
+
* GET handler - retrieves anonymous session preferences
|
|
13
|
+
*/
|
|
14
|
+
export declare function GET(request: NextRequest): Promise<NextResponse<{
|
|
15
|
+
success: boolean;
|
|
16
|
+
data: {
|
|
17
|
+
id: string;
|
|
18
|
+
preferences: AnonSessionPreferences;
|
|
19
|
+
metrics: import("../../lib/anon-session").AnonSessionMetrics;
|
|
20
|
+
};
|
|
21
|
+
}> | NextResponse<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
error: string;
|
|
24
|
+
}>>;
|
|
25
|
+
/**
|
|
26
|
+
* POST handler - updates anonymous session preferences
|
|
27
|
+
*/
|
|
28
|
+
export declare function POST(request: NextRequest): Promise<NextResponse<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
error: string;
|
|
31
|
+
}> | NextResponse<{
|
|
32
|
+
success: boolean;
|
|
33
|
+
data: {
|
|
34
|
+
id: string;
|
|
35
|
+
preferences: AnonSessionPreferences;
|
|
36
|
+
};
|
|
37
|
+
}>>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Anonymous Session Preferences API Handler
|
|
4
|
+
*
|
|
5
|
+
* GET /api/anon/preferences - Get current preferences
|
|
6
|
+
* POST /api/anon/preferences - Update preferences
|
|
7
|
+
*
|
|
8
|
+
* Sets a cookie to track anonymous visitors and stores preferences in Redis.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.GET = GET;
|
|
12
|
+
exports.POST = POST;
|
|
13
|
+
const server_1 = require("next/server");
|
|
14
|
+
const headers_1 = require("next/headers");
|
|
15
|
+
const anon_session_1 = require("../../lib/anon-session");
|
|
16
|
+
const COOKIE_MAX_AGE = 90 * 24 * 60 * 60; // 90 days in seconds
|
|
17
|
+
/**
|
|
18
|
+
* GET handler - retrieves anonymous session preferences
|
|
19
|
+
*/
|
|
20
|
+
async function GET(request) {
|
|
21
|
+
try {
|
|
22
|
+
const cookieStore = await (0, headers_1.cookies)();
|
|
23
|
+
let anonId = cookieStore.get(anon_session_1.ANON_COOKIE_NAME)?.value;
|
|
24
|
+
// Get or create session
|
|
25
|
+
const session = await (0, anon_session_1.getOrCreateAnonSession)(anonId);
|
|
26
|
+
// Build response
|
|
27
|
+
const response = server_1.NextResponse.json({
|
|
28
|
+
success: true,
|
|
29
|
+
data: {
|
|
30
|
+
id: session.id,
|
|
31
|
+
preferences: session.preferences,
|
|
32
|
+
metrics: session.metrics,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
// Set cookie if it's a new session
|
|
36
|
+
if (!anonId || anonId !== session.id) {
|
|
37
|
+
response.cookies.set(anon_session_1.ANON_COOKIE_NAME, session.id, {
|
|
38
|
+
httpOnly: true,
|
|
39
|
+
secure: process.env.NODE_ENV === 'production',
|
|
40
|
+
sameSite: 'lax',
|
|
41
|
+
maxAge: COOKIE_MAX_AGE,
|
|
42
|
+
path: '/',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return response;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error('[ANON-PREFERENCES] GET error:', error);
|
|
49
|
+
return server_1.NextResponse.json({ success: false, error: 'Failed to get preferences' }, { status: 500 });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* POST handler - updates anonymous session preferences
|
|
54
|
+
*/
|
|
55
|
+
async function POST(request) {
|
|
56
|
+
try {
|
|
57
|
+
const cookieStore = await (0, headers_1.cookies)();
|
|
58
|
+
let anonId = cookieStore.get(anon_session_1.ANON_COOKIE_NAME)?.value;
|
|
59
|
+
// Get or create session first
|
|
60
|
+
const session = await (0, anon_session_1.getOrCreateAnonSession)(anonId);
|
|
61
|
+
anonId = session.id;
|
|
62
|
+
// Parse body for preferences to update
|
|
63
|
+
const body = await request.json();
|
|
64
|
+
const preferences = body.preferences || body;
|
|
65
|
+
// Validate preferences
|
|
66
|
+
if (typeof preferences !== 'object') {
|
|
67
|
+
return server_1.NextResponse.json({ success: false, error: 'Invalid preferences format' }, { status: 400 });
|
|
68
|
+
}
|
|
69
|
+
// Update preferences
|
|
70
|
+
const updatedSession = await (0, anon_session_1.updateAnonPreferences)(anonId, preferences);
|
|
71
|
+
if (!updatedSession) {
|
|
72
|
+
return server_1.NextResponse.json({ success: false, error: 'Session not found' }, { status: 404 });
|
|
73
|
+
}
|
|
74
|
+
// Build response
|
|
75
|
+
const response = server_1.NextResponse.json({
|
|
76
|
+
success: true,
|
|
77
|
+
data: {
|
|
78
|
+
id: updatedSession.id,
|
|
79
|
+
preferences: updatedSession.preferences,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
// Ensure cookie is set
|
|
83
|
+
response.cookies.set(anon_session_1.ANON_COOKIE_NAME, anonId, {
|
|
84
|
+
httpOnly: true,
|
|
85
|
+
secure: process.env.NODE_ENV === 'production',
|
|
86
|
+
sameSite: 'lax',
|
|
87
|
+
maxAge: COOKIE_MAX_AGE,
|
|
88
|
+
path: '/',
|
|
89
|
+
});
|
|
90
|
+
return response;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('[ANON-PREFERENCES] POST error:', error);
|
|
94
|
+
return server_1.NextResponse.json({ success: false, error: 'Failed to update preferences' }, { status: 500 });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = GET;
|
|
4
|
+
const server_1 = require("next/server");
|
|
5
|
+
const env_1 = require("../../config/env");
|
|
6
|
+
const logger_1 = require("../../config/logger");
|
|
7
|
+
async function GET(_req) {
|
|
8
|
+
try {
|
|
9
|
+
const url = `${env_1.ENV_CONFIG.IDP_URL}${env_1.API_ENDPOINTS.externalAuth.jwks}`;
|
|
10
|
+
const res = await fetch(url, { headers: { 'Accept': 'application/json' } });
|
|
11
|
+
const bodyText = await res.text();
|
|
12
|
+
try {
|
|
13
|
+
const json = JSON.parse(bodyText);
|
|
14
|
+
return server_1.NextResponse.json(json, { status: res.status });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
logger_1.logger.error('[AUTH_JWKS] Upstream returned non-JSON', { status: res.status, bodyText: bodyText?.slice(0, 200) });
|
|
18
|
+
return server_1.NextResponse.json({ error: 'Invalid JWKS response' }, { status: 502 });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return server_1.NextResponse.json({ error: 'Failed to fetch JWKS' }, { status: 502 });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Login API Handler
|
|
3
|
+
*
|
|
4
|
+
* Handles user authentication against the external IDP service.
|
|
5
|
+
* This handler is designed to be imported and used by Next.js applications
|
|
6
|
+
* using the @payez/next-mvp package.
|
|
7
|
+
*
|
|
8
|
+
* @version 2.0
|
|
9
|
+
* @requires No authentication (public endpoint)
|
|
10
|
+
*/
|
|
11
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
12
|
+
interface LoginConfig {
|
|
13
|
+
idpBaseUrl: string;
|
|
14
|
+
clientId: string;
|
|
15
|
+
loginEndpoint?: string;
|
|
16
|
+
clientType?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a login handler for Next.js API routes
|
|
20
|
+
*
|
|
21
|
+
* @param config Configuration for IDP connection
|
|
22
|
+
* @returns Next.js POST handler function
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // In your app's /app/api/auth/login/route.ts
|
|
27
|
+
* import { createLoginHandler } from '@payez/next-mvp/api-handlers/auth/login';
|
|
28
|
+
*
|
|
29
|
+
* export const POST = createLoginHandler({
|
|
30
|
+
* idpBaseUrl: process.env.IDP_URL!,
|
|
31
|
+
* clientId: process.env.CLIENT_ID!,
|
|
32
|
+
* loginEndpoint: '/api/ExternalAuth/login'
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function createLoginHandler(config: LoginConfig): (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
37
|
+
/**
|
|
38
|
+
* Default export for backward compatibility
|
|
39
|
+
* Requires environment variables: IDP_URL, CLIENT_ID
|
|
40
|
+
*/
|
|
41
|
+
export declare const POST: (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Login API Handler
|
|
4
|
+
*
|
|
5
|
+
* Handles user authentication against the external IDP service.
|
|
6
|
+
* This handler is designed to be imported and used by Next.js applications
|
|
7
|
+
* using the @payez/next-mvp package.
|
|
8
|
+
*
|
|
9
|
+
* @version 2.0
|
|
10
|
+
* @requires No authentication (public endpoint)
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.POST = void 0;
|
|
14
|
+
exports.createLoginHandler = createLoginHandler;
|
|
15
|
+
const server_1 = require("next/server");
|
|
16
|
+
// Add protection headers to all responses
|
|
17
|
+
function addSecurityHeaders(response) {
|
|
18
|
+
// Content Security Policy - restrictive for auth endpoints
|
|
19
|
+
response.headers.set('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self';");
|
|
20
|
+
// Prevent clickjacking
|
|
21
|
+
response.headers.set('X-Frame-Options', 'DENY');
|
|
22
|
+
// Prevent MIME type sniffing
|
|
23
|
+
response.headers.set('X-Content-Type-Options', 'nosniff');
|
|
24
|
+
// Enable XSS protection
|
|
25
|
+
response.headers.set('X-XSS-Protection', '1; mode=block');
|
|
26
|
+
// Strict transport security for HTTPS
|
|
27
|
+
response.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload');
|
|
28
|
+
// Referrer policy
|
|
29
|
+
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
30
|
+
// Permissions policy
|
|
31
|
+
response.headers.set('Permissions-Policy', 'geolocation=(), microphone=(), camera=(), payment=(), usb=(), magnetometer=(), gyroscope=(), accelerometer=()');
|
|
32
|
+
// Cache control for sensitive auth endpoints
|
|
33
|
+
response.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
|
34
|
+
response.headers.set('Pragma', 'no-cache');
|
|
35
|
+
response.headers.set('Expires', '0');
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a login handler for Next.js API routes
|
|
40
|
+
*
|
|
41
|
+
* @param config Configuration for IDP connection
|
|
42
|
+
* @returns Next.js POST handler function
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // In your app's /app/api/auth/login/route.ts
|
|
47
|
+
* import { createLoginHandler } from '@payez/next-mvp/api-handlers/auth/login';
|
|
48
|
+
*
|
|
49
|
+
* export const POST = createLoginHandler({
|
|
50
|
+
* idpBaseUrl: process.env.IDP_URL!,
|
|
51
|
+
* clientId: process.env.CLIENT_ID!,
|
|
52
|
+
* loginEndpoint: '/api/ExternalAuth/login'
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function createLoginHandler(config) {
|
|
57
|
+
const { idpBaseUrl, clientId, loginEndpoint = '/api/ExternalAuth/login', clientType = 'partner' } = config;
|
|
58
|
+
return async function POST(req) {
|
|
59
|
+
let body;
|
|
60
|
+
try {
|
|
61
|
+
body = await req.json();
|
|
62
|
+
}
|
|
63
|
+
catch (parseError) {
|
|
64
|
+
return server_1.NextResponse.json({ error: 'Invalid JSON format' }, { status: 400 });
|
|
65
|
+
}
|
|
66
|
+
const { username_or_email, password, client_type, two_factor_code, two_factor_recovery_code } = body;
|
|
67
|
+
// Validate required fields
|
|
68
|
+
if (!username_or_email || typeof username_or_email !== 'string' || username_or_email.trim() === '') {
|
|
69
|
+
return server_1.NextResponse.json({ error: 'username_or_email is required' }, { status: 400 });
|
|
70
|
+
}
|
|
71
|
+
if (!password || typeof password !== 'string' || password.trim() === '') {
|
|
72
|
+
return server_1.NextResponse.json({ error: 'Password is required' }, { status: 400 });
|
|
73
|
+
}
|
|
74
|
+
const idpUrl = `${idpBaseUrl}${loginEndpoint}`;
|
|
75
|
+
const payload = {
|
|
76
|
+
username_or_email,
|
|
77
|
+
password,
|
|
78
|
+
client_id: clientId,
|
|
79
|
+
client_type: client_type || clientType // Use provided client_type or config default
|
|
80
|
+
};
|
|
81
|
+
// Add optional 2FA fields if provided
|
|
82
|
+
if (two_factor_code) {
|
|
83
|
+
payload.two_factor_code = two_factor_code;
|
|
84
|
+
}
|
|
85
|
+
if (two_factor_recovery_code) {
|
|
86
|
+
payload.two_factor_recovery_code = two_factor_recovery_code;
|
|
87
|
+
}
|
|
88
|
+
// Extract client headers for forwarding to IDP
|
|
89
|
+
const clientHeaders = {};
|
|
90
|
+
// Forward client IP if available
|
|
91
|
+
const clientIp = req.headers.get('x-forwarded-for') || req.headers.get('x-real-ip');
|
|
92
|
+
if (clientIp) {
|
|
93
|
+
clientHeaders['X-Forwarded-For'] = clientIp.split(',')[0].trim();
|
|
94
|
+
}
|
|
95
|
+
// Forward user agent if available
|
|
96
|
+
const userAgent = req.headers.get('user-agent');
|
|
97
|
+
if (userAgent) {
|
|
98
|
+
clientHeaders['User-Agent'] = userAgent;
|
|
99
|
+
}
|
|
100
|
+
const headers = {
|
|
101
|
+
'Content-Type': 'application/json',
|
|
102
|
+
'Accept': 'application/json',
|
|
103
|
+
'Cookie': 'X-Device-Id=payez-PayEz-6c8201c35c1b44c9b2e823b36b95a718',
|
|
104
|
+
...clientHeaders
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
const backendResponse = await fetch(idpUrl, {
|
|
108
|
+
method: 'POST',
|
|
109
|
+
headers,
|
|
110
|
+
body: JSON.stringify(payload),
|
|
111
|
+
});
|
|
112
|
+
const rawText = await backendResponse.text();
|
|
113
|
+
let data;
|
|
114
|
+
try {
|
|
115
|
+
data = JSON.parse(rawText);
|
|
116
|
+
}
|
|
117
|
+
catch (jsonError) {
|
|
118
|
+
console.error('[LOGIN] IDP returned non-JSON response', {
|
|
119
|
+
response: rawText,
|
|
120
|
+
status: backendResponse.status
|
|
121
|
+
});
|
|
122
|
+
return server_1.NextResponse.json({ error: 'Invalid response from authentication service' }, { status: 502 });
|
|
123
|
+
}
|
|
124
|
+
if (!backendResponse.ok) {
|
|
125
|
+
// Handle rate limiting specifically
|
|
126
|
+
if (backendResponse.status === 429) {
|
|
127
|
+
const retryAfter = backendResponse.headers.get('retry-after');
|
|
128
|
+
const retryAfterSeconds = retryAfter ? parseInt(retryAfter) : 60;
|
|
129
|
+
return addSecurityHeaders(server_1.NextResponse.json({
|
|
130
|
+
success: false,
|
|
131
|
+
error: 'RATE_LIMIT_EXCEEDED',
|
|
132
|
+
message: 'Too many login attempts. Please try again later.',
|
|
133
|
+
retryAfter: retryAfterSeconds
|
|
134
|
+
}, { status: 429 }));
|
|
135
|
+
}
|
|
136
|
+
// Pass through error from IDP
|
|
137
|
+
console.error('[LOGIN] IDP service error', {
|
|
138
|
+
status: backendResponse.status,
|
|
139
|
+
error: data
|
|
140
|
+
});
|
|
141
|
+
return addSecurityHeaders(server_1.NextResponse.json(data, { status: backendResponse.status }));
|
|
142
|
+
}
|
|
143
|
+
if (!data.success) {
|
|
144
|
+
// IDP returned a canonical error envelope with HTTP 200
|
|
145
|
+
console.error('[LOGIN] IDP authentication failure', { error: data });
|
|
146
|
+
return addSecurityHeaders(server_1.NextResponse.json(data, { status: 200 }));
|
|
147
|
+
}
|
|
148
|
+
// Normalize response shape for NextAuth authorize()
|
|
149
|
+
const normalized = {
|
|
150
|
+
success: data?.success === true,
|
|
151
|
+
result: (data?.data && data?.data?.result) ? data.data.result : (data?.result ?? data),
|
|
152
|
+
// Preserve original payload for debugging/compatibility
|
|
153
|
+
original: data
|
|
154
|
+
};
|
|
155
|
+
return addSecurityHeaders(server_1.NextResponse.json(normalized));
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
// Handle network and other errors
|
|
159
|
+
console.error('[LOGIN] FETCH FAILED:', {
|
|
160
|
+
error: error instanceof Error ? error.message : String(error),
|
|
161
|
+
idpUrl
|
|
162
|
+
});
|
|
163
|
+
if (error instanceof Error && error.message.includes('fetch')) {
|
|
164
|
+
return server_1.NextResponse.json({ error: 'Unable to connect to authentication service' }, { status: 503 });
|
|
165
|
+
}
|
|
166
|
+
return server_1.NextResponse.json({ error: 'An unexpected error occurred during login' }, { status: 500 });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Default export for backward compatibility
|
|
172
|
+
* Requires environment variables: IDP_URL, CLIENT_ID
|
|
173
|
+
*/
|
|
174
|
+
exports.POST = createLoginHandler({
|
|
175
|
+
idpBaseUrl: process.env.IDP_URL,
|
|
176
|
+
clientId: process.env.CLIENT_ID || 'payez_default_client',
|
|
177
|
+
loginEndpoint: '/api/ExternalAuth/login'
|
|
178
|
+
});
|