create-nextdevtpl 2.6.0
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/README.md +29 -0
- package/catalog.json +385 -0
- package/dist/catalog.d.ts +3 -0
- package/dist/catalog.js +112 -0
- package/dist/catalog.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +115 -0
- package/dist/cli.js.map +1 -0
- package/dist/filesystem.d.ts +10 -0
- package/dist/filesystem.js +86 -0
- package/dist/filesystem.js.map +1 -0
- package/dist/generate.d.ts +5 -0
- package/dist/generate.js +758 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/selection.d.ts +2 -0
- package/dist/selection.js +111 -0
- package/dist/selection.js.map +1 -0
- package/dist/service-templates.d.ts +4 -0
- package/dist/service-templates.js +180 -0
- package/dist/service-templates.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
- package/template/.dockerignore +14 -0
- package/template/.env.example +282 -0
- package/template/.gitattributes +17 -0
- package/template/.node-version +1 -0
- package/template/Dockerfile +45 -0
- package/template/LICENSE +21 -0
- package/template/README.md +267 -0
- package/template/biome.json +68 -0
- package/template/cloudflare/templates/logger.ts +162 -0
- package/template/cloudflare/templates/mail/server.ts +6 -0
- package/template/cloudflare/templates/mail/templates.ts +87 -0
- package/template/cloudflare/templates/mail/utils.ts +69 -0
- package/template/cloudflare/worker.mjs +25 -0
- package/template/components.json +22 -0
- package/template/compose.yaml +74 -0
- package/template/deploy/check-health.mjs +25 -0
- package/template/deploy/docker/README.md +14 -0
- package/template/deploy/server/README.md +24 -0
- package/template/deploy/server/build.sh +24 -0
- package/template/deploy/server/nextdevtpl.service +19 -0
- package/template/deploy/server/start.sh +19 -0
- package/template/deploy/vercel/README.md +16 -0
- package/template/deploy/verify-production-health.mjs +86 -0
- package/template/drizzle.config.ts +47 -0
- package/template/gitignore +62 -0
- package/template/manifest.json +35 -0
- package/template/messages/en.json +766 -0
- package/template/messages/zh.json +762 -0
- package/template/next.config.mjs +28 -0
- package/template/open-next.config.ts +3 -0
- package/template/package.json +125 -0
- package/template/pnpm-lock.yaml +15901 -0
- package/template/postcss.config.mjs +7 -0
- package/template/public/file.svg +1 -0
- package/template/public/globe.svg +1 -0
- package/template/public/logo.svg +6 -0
- package/template/public/next.svg +1 -0
- package/template/public/vercel.svg +1 -0
- package/template/public/window.svg +1 -0
- package/template/sentry.client.config.ts +10 -0
- package/template/sentry.edge.config.ts +10 -0
- package/template/sentry.server.config.ts +10 -0
- package/template/source.config.ts +59 -0
- package/template/src/adapters/ai/anthropic.ts +113 -0
- package/template/src/adapters/ai/index.ts +6 -0
- package/template/src/adapters/ai/openai-compatible.ts +88 -0
- package/template/src/adapters/ai/workers-ai.ts +63 -0
- package/template/src/adapters/index.ts +10 -0
- package/template/src/adapters/jobs/cloudflare-workflows.ts +46 -0
- package/template/src/adapters/jobs/index.ts +5 -0
- package/template/src/adapters/jobs/inngest/adapter.ts +29 -0
- package/template/src/adapters/jobs/inngest/client.ts +8 -0
- package/template/src/adapters/jobs/inngest/functions.ts +17 -0
- package/template/src/adapters/jobs/inngest/handler.ts +6 -0
- package/template/src/adapters/jobs/inngest/index.ts +4 -0
- package/template/src/adapters/mail/cloudflare-email.ts +50 -0
- package/template/src/adapters/mail/disabled.ts +17 -0
- package/template/src/adapters/mail/index.ts +7 -0
- package/template/src/adapters/mail/resend.ts +76 -0
- package/template/src/adapters/mail/smtp.ts +82 -0
- package/template/src/adapters/payment/creem.ts +269 -0
- package/template/src/adapters/payment/index.ts +2 -0
- package/template/src/adapters/payment/stripe.ts +302 -0
- package/template/src/adapters/rate-limit/cloudflare.ts +42 -0
- package/template/src/adapters/rate-limit/index.ts +6 -0
- package/template/src/adapters/rate-limit/noop.ts +27 -0
- package/template/src/adapters/rate-limit/upstash.ts +113 -0
- package/template/src/adapters/registry.ts +228 -0
- package/template/src/adapters/storage/index.ts +3 -0
- package/template/src/adapters/storage/r2-binding.ts +105 -0
- package/template/src/adapters/storage/s3-compatible.ts +149 -0
- package/template/src/app/[locale]/(admin)/admin/layout.tsx +36 -0
- package/template/src/app/[locale]/(admin)/admin/page.tsx +345 -0
- package/template/src/app/[locale]/(admin)/admin/tickets/[id]/page.tsx +261 -0
- package/template/src/app/[locale]/(admin)/admin/tickets/page.tsx +236 -0
- package/template/src/app/[locale]/(admin)/admin/users/page.tsx +557 -0
- package/template/src/app/[locale]/(auth)/forgot-password/page.tsx +9 -0
- package/template/src/app/[locale]/(auth)/layout.tsx +28 -0
- package/template/src/app/[locale]/(auth)/sign-in/page.tsx +9 -0
- package/template/src/app/[locale]/(auth)/sign-up/page.tsx +9 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/credits/buy/buy-credits-view.tsx +170 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/credits/buy/page.tsx +12 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/credits/page.tsx +5 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/loading.tsx +41 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/page.tsx +299 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx +38 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/support/[id]/page.tsx +220 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/support/new/page.tsx +183 -0
- package/template/src/app/[locale]/(dashboard)/dashboard/support/page.tsx +145 -0
- package/template/src/app/[locale]/(dashboard)/layout.tsx +35 -0
- package/template/src/app/[locale]/(marketing)/blog/[slug]/page.tsx +178 -0
- package/template/src/app/[locale]/(marketing)/blog/blog-post-card.tsx +95 -0
- package/template/src/app/[locale]/(marketing)/blog/page.tsx +127 -0
- package/template/src/app/[locale]/(marketing)/demo/plan-badges/page.tsx +36 -0
- package/template/src/app/[locale]/(marketing)/layout.tsx +15 -0
- package/template/src/app/[locale]/(marketing)/legal/[slug]/page.tsx +130 -0
- package/template/src/app/[locale]/(marketing)/page.tsx +94 -0
- package/template/src/app/[locale]/(marketing)/pseo/[slug]/page.tsx +68 -0
- package/template/src/app/[locale]/(marketing)/pseo/page.tsx +137 -0
- package/template/src/app/[locale]/docs/[[...slug]]/page.tsx +63 -0
- package/template/src/app/[locale]/docs/layout.tsx +39 -0
- package/template/src/app/[locale]/layout.tsx +80 -0
- package/template/src/app/[locale]/opengraph-image.tsx +20 -0
- package/template/src/app/[locale]/twitter-image.tsx +20 -0
- package/template/src/app/api/auth/[...all]/route.ts +20 -0
- package/template/src/app/api/health/route.ts +45 -0
- package/template/src/app/api/inngest/route.ts +12 -0
- package/template/src/app/api/jobs/credits/expire/route.ts +102 -0
- package/template/src/app/api/search/route.ts +17 -0
- package/template/src/app/api/upload/presigned/route.ts +98 -0
- package/template/src/app/api/webhooks/payment/route.ts +363 -0
- package/template/src/app/globals.css +406 -0
- package/template/src/app/icon.svg +6 -0
- package/template/src/app/image-proxy/[...path]/route.ts +137 -0
- package/template/src/app/layout.tsx +73 -0
- package/template/src/app/robots.ts +29 -0
- package/template/src/app/sitemap.ts +68 -0
- package/template/src/components/motion/reveal.tsx +49 -0
- package/template/src/components/seo/json-ld.tsx +87 -0
- package/template/src/components/seo/og-image-template.tsx +118 -0
- package/template/src/components/ui/accordion.tsx +66 -0
- package/template/src/components/ui/alert-dialog.tsx +195 -0
- package/template/src/components/ui/avatar.tsx +53 -0
- package/template/src/components/ui/badge.tsx +46 -0
- package/template/src/components/ui/button.tsx +65 -0
- package/template/src/components/ui/card.tsx +92 -0
- package/template/src/components/ui/checkbox.tsx +32 -0
- package/template/src/components/ui/collapsible.tsx +33 -0
- package/template/src/components/ui/dialog.tsx +124 -0
- package/template/src/components/ui/dropdown-menu.tsx +257 -0
- package/template/src/components/ui/form.tsx +233 -0
- package/template/src/components/ui/index.ts +2 -0
- package/template/src/components/ui/input.tsx +21 -0
- package/template/src/components/ui/label.tsx +24 -0
- package/template/src/components/ui/navigation-menu.tsx +167 -0
- package/template/src/components/ui/pagination.tsx +125 -0
- package/template/src/components/ui/popover.tsx +48 -0
- package/template/src/components/ui/progress.tsx +27 -0
- package/template/src/components/ui/radio-group.tsx +45 -0
- package/template/src/components/ui/select.tsx +190 -0
- package/template/src/components/ui/separator.tsx +28 -0
- package/template/src/components/ui/sheet.tsx +140 -0
- package/template/src/components/ui/switch.tsx +31 -0
- package/template/src/components/ui/tabs.tsx +75 -0
- package/template/src/components/ui/textarea.tsx +18 -0
- package/template/src/config/index.ts +31 -0
- package/template/src/config/nav.ts +238 -0
- package/template/src/config/payment.ts +282 -0
- package/template/src/config/site.ts +53 -0
- package/template/src/config/subscription-plan.ts +164 -0
- package/template/src/content/blog/en/hello-world.mdx +48 -0
- package/template/src/content/blog/zh/hello-world.mdx +48 -0
- package/template/src/content/blog/zh/nextdevtpl-linuxdo-intro.mdx +98 -0
- package/template/src/content/docs/en/admin-and-support.mdx +65 -0
- package/template/src/content/docs/en/authentication.mdx +71 -0
- package/template/src/content/docs/en/background-jobs.mdx +53 -0
- package/template/src/content/docs/en/configuration.mdx +71 -0
- package/template/src/content/docs/en/credits.mdx +69 -0
- package/template/src/content/docs/en/customization.mdx +95 -0
- package/template/src/content/docs/en/database.mdx +66 -0
- package/template/src/content/docs/en/deployment.mdx +62 -0
- package/template/src/content/docs/en/email.mdx +48 -0
- package/template/src/content/docs/en/index.mdx +48 -0
- package/template/src/content/docs/en/internationalization.mdx +78 -0
- package/template/src/content/docs/en/meta.json +22 -0
- package/template/src/content/docs/en/observability.mdx +69 -0
- package/template/src/content/docs/en/payments.mdx +64 -0
- package/template/src/content/docs/en/project-structure.mdx +82 -0
- package/template/src/content/docs/en/quick-start.mdx +113 -0
- package/template/src/content/docs/en/storage.mdx +51 -0
- package/template/src/content/docs/zh/admin-and-support.mdx +65 -0
- package/template/src/content/docs/zh/authentication.mdx +71 -0
- package/template/src/content/docs/zh/background-jobs.mdx +53 -0
- package/template/src/content/docs/zh/configuration.mdx +70 -0
- package/template/src/content/docs/zh/credits.mdx +69 -0
- package/template/src/content/docs/zh/customization.mdx +95 -0
- package/template/src/content/docs/zh/database.mdx +66 -0
- package/template/src/content/docs/zh/deployment.mdx +61 -0
- package/template/src/content/docs/zh/email.mdx +47 -0
- package/template/src/content/docs/zh/index.mdx +48 -0
- package/template/src/content/docs/zh/internationalization.mdx +78 -0
- package/template/src/content/docs/zh/meta.json +22 -0
- package/template/src/content/docs/zh/observability.mdx +68 -0
- package/template/src/content/docs/zh/payments.mdx +64 -0
- package/template/src/content/docs/zh/project-structure.mdx +82 -0
- package/template/src/content/docs/zh/quick-start.mdx +110 -0
- package/template/src/content/docs/zh/storage.mdx +51 -0
- package/template/src/content/legal/en/cookie-policy.mdx +78 -0
- package/template/src/content/legal/en/privacy.mdx +131 -0
- package/template/src/content/legal/en/terms.mdx +93 -0
- package/template/src/content/legal/zh/cookie-policy.mdx +78 -0
- package/template/src/content/legal/zh/privacy.mdx +131 -0
- package/template/src/content/legal/zh/terms.mdx +92 -0
- package/template/src/core/modules/contract.ts +225 -0
- package/template/src/core/modules/index.ts +1 -0
- package/template/src/core/services/ai.ts +31 -0
- package/template/src/core/services/common.ts +112 -0
- package/template/src/core/services/index.ts +8 -0
- package/template/src/core/services/jobs.ts +24 -0
- package/template/src/core/services/mail.ts +35 -0
- package/template/src/core/services/manifest.ts +51 -0
- package/template/src/core/services/payment.ts +92 -0
- package/template/src/core/services/rate-limit.ts +47 -0
- package/template/src/core/services/storage.ts +42 -0
- package/template/src/db/index.ts +71 -0
- package/template/src/db/schema/auth.ts +67 -0
- package/template/src/db/schema/credits.ts +94 -0
- package/template/src/db/schema/index.ts +5 -0
- package/template/src/db/schema/mail.ts +14 -0
- package/template/src/db/schema/subscription.ts +21 -0
- package/template/src/db/schema/support.ts +56 -0
- package/template/src/db/schema.ts +2 -0
- package/template/src/features/admin/components/admin-sidebar.tsx +213 -0
- package/template/src/features/admin/components/index.ts +2 -0
- package/template/src/features/admin/index.ts +3 -0
- package/template/src/features/admin/manifest.ts +41 -0
- package/template/src/features/analytics/components/analytics.tsx +62 -0
- package/template/src/features/analytics/components/index.ts +2 -0
- package/template/src/features/analytics/index.ts +3 -0
- package/template/src/features/analytics/manifest.ts +13 -0
- package/template/src/features/auth/components/auth-brand-panel.tsx +82 -0
- package/template/src/features/auth/components/auth-error-alert.tsx +28 -0
- package/template/src/features/auth/components/auth-footer.tsx +52 -0
- package/template/src/features/auth/components/auth-logo.tsx +30 -0
- package/template/src/features/auth/components/forgot-password-form.tsx +146 -0
- package/template/src/features/auth/components/index.ts +9 -0
- package/template/src/features/auth/components/sign-in-form.tsx +241 -0
- package/template/src/features/auth/components/sign-up-form.tsx +307 -0
- package/template/src/features/auth/index.ts +3 -0
- package/template/src/features/auth/manifest.ts +30 -0
- package/template/src/features/blog/components/blog-post-item.tsx +72 -0
- package/template/src/features/blog/components/index.ts +1 -0
- package/template/src/features/blog/data/mock-posts.ts +62 -0
- package/template/src/features/blog/index.ts +3 -0
- package/template/src/features/blog/manifest.ts +22 -0
- package/template/src/features/credits/account.ts +76 -0
- package/template/src/features/credits/actions.ts +427 -0
- package/template/src/features/credits/components/credit-balance-badge.tsx +54 -0
- package/template/src/features/credits/components/credit-usage-section.tsx +160 -0
- package/template/src/features/credits/components/index.ts +7 -0
- package/template/src/features/credits/components/transaction-history.tsx +346 -0
- package/template/src/features/credits/config.ts +70 -0
- package/template/src/features/credits/consume.ts +140 -0
- package/template/src/features/credits/core.ts +23 -0
- package/template/src/features/credits/errors.ts +26 -0
- package/template/src/features/credits/expire.ts +112 -0
- package/template/src/features/credits/grant.ts +168 -0
- package/template/src/features/credits/index.ts +6 -0
- package/template/src/features/credits/manifest.ts +36 -0
- package/template/src/features/credits/query.ts +65 -0
- package/template/src/features/credits/types.ts +48 -0
- package/template/src/features/dashboard/components/index.ts +3 -0
- package/template/src/features/dashboard/components/main-wrapper.tsx +100 -0
- package/template/src/features/dashboard/components/sidebar.tsx +341 -0
- package/template/src/features/dashboard/context/index.ts +2 -0
- package/template/src/features/dashboard/context/sidebar-context.tsx +72 -0
- package/template/src/features/dashboard/index.ts +4 -0
- package/template/src/features/dashboard/manifest.ts +28 -0
- package/template/src/features/mail/actions.ts +175 -0
- package/template/src/features/mail/index.ts +5 -0
- package/template/src/features/mail/manifest.ts +13 -0
- package/template/src/features/mail/server.ts +8 -0
- package/template/src/features/mail/templates/index.ts +11 -0
- package/template/src/features/mail/templates/primary-action-email.tsx +224 -0
- package/template/src/features/mail/templates/welcome-email.tsx +121 -0
- package/template/src/features/mail/utils.ts +190 -0
- package/template/src/features/marketing/components/animated-price.tsx +51 -0
- package/template/src/features/marketing/components/cookie-consent.tsx +255 -0
- package/template/src/features/marketing/components/cta-section.tsx +50 -0
- package/template/src/features/marketing/components/faq-section.tsx +59 -0
- package/template/src/features/marketing/components/feature-grid.tsx +80 -0
- package/template/src/features/marketing/components/footer.tsx +128 -0
- package/template/src/features/marketing/components/header.tsx +255 -0
- package/template/src/features/marketing/components/hero-section.tsx +323 -0
- package/template/src/features/marketing/components/how-it-works.tsx +115 -0
- package/template/src/features/marketing/components/index.ts +14 -0
- package/template/src/features/marketing/components/nav-menu.tsx +236 -0
- package/template/src/features/marketing/components/pricing-section.tsx +446 -0
- package/template/src/features/marketing/components/testimonials.tsx +59 -0
- package/template/src/features/marketing/components/use-cases-section.tsx +78 -0
- package/template/src/features/marketing/index.ts +3 -0
- package/template/src/features/marketing/manifest.ts +35 -0
- package/template/src/features/payment/actions.ts +182 -0
- package/template/src/features/payment/index.ts +4 -0
- package/template/src/features/payment/manifest.ts +18 -0
- package/template/src/features/payment/server.ts +7 -0
- package/template/src/features/payment/types.ts +202 -0
- package/template/src/features/pseo/components/index.ts +6 -0
- package/template/src/features/pseo/components/pseo-cta.tsx +51 -0
- package/template/src/features/pseo/components/pseo-faq.tsx +40 -0
- package/template/src/features/pseo/components/pseo-feature-grid.tsx +74 -0
- package/template/src/features/pseo/components/pseo-hero.tsx +106 -0
- package/template/src/features/pseo/components/pseo-related.tsx +62 -0
- package/template/src/features/pseo/components/pseo-use-cases.tsx +50 -0
- package/template/src/features/pseo/data/pseo-pages.json +534 -0
- package/template/src/features/pseo/index.ts +4 -0
- package/template/src/features/pseo/lib/pseo-data.ts +140 -0
- package/template/src/features/pseo/manifest.ts +22 -0
- package/template/src/features/settings/actions/delete-account.ts +50 -0
- package/template/src/features/settings/actions/index.ts +3 -0
- package/template/src/features/settings/actions/update-profile.ts +49 -0
- package/template/src/features/settings/components/billing-section.tsx +283 -0
- package/template/src/features/settings/components/index.ts +3 -0
- package/template/src/features/settings/components/profile-form.tsx +154 -0
- package/template/src/features/settings/components/security-section.tsx +158 -0
- package/template/src/features/settings/components/settings-profile-view.tsx +506 -0
- package/template/src/features/settings/index.ts +5 -0
- package/template/src/features/settings/manifest.ts +28 -0
- package/template/src/features/settings/schemas/index.ts +2 -0
- package/template/src/features/settings/schemas/update-profile.ts +21 -0
- package/template/src/features/shared/components/cookie-settings-dialog.tsx +282 -0
- package/template/src/features/shared/components/index.ts +5 -0
- package/template/src/features/shared/components/language-switcher.tsx +82 -0
- package/template/src/features/shared/components/max-width-wrapper.tsx +49 -0
- package/template/src/features/shared/components/mode-toggle.tsx +119 -0
- package/template/src/features/shared/icons/google-icon.tsx +39 -0
- package/template/src/features/shared/icons/index.ts +7 -0
- package/template/src/features/shared/index.ts +5 -0
- package/template/src/features/shared/manifest.ts +13 -0
- package/template/src/features/shared/providers.tsx +59 -0
- package/template/src/features/storage/actions.ts +107 -0
- package/template/src/features/storage/index.ts +6 -0
- package/template/src/features/storage/manifest.ts +22 -0
- package/template/src/features/storage/types.ts +143 -0
- package/template/src/features/storage/utils.ts +85 -0
- package/template/src/features/storage/validation.ts +151 -0
- package/template/src/features/subscription/actions/get-user-plan.ts +26 -0
- package/template/src/features/subscription/actions/index.ts +5 -0
- package/template/src/features/subscription/components/current-plan-badge.tsx +18 -0
- package/template/src/features/subscription/components/index.ts +6 -0
- package/template/src/features/subscription/components/plan-badge.tsx +98 -0
- package/template/src/features/subscription/index.ts +25 -0
- package/template/src/features/subscription/manifest.ts +13 -0
- package/template/src/features/subscription/services/user-plan.ts +181 -0
- package/template/src/features/support/actions/admin-ticket.ts +172 -0
- package/template/src/features/support/actions/admin-users.ts +295 -0
- package/template/src/features/support/actions/index.ts +22 -0
- package/template/src/features/support/actions/ticket.ts +12 -0
- package/template/src/features/support/actions/user-ticket.ts +153 -0
- package/template/src/features/support/components/admin-ticket-reply-form.tsx +109 -0
- package/template/src/features/support/components/admin-ticket-status-select.tsx +119 -0
- package/template/src/features/support/components/index.ts +6 -0
- package/template/src/features/support/components/ticket-message-form.tsx +99 -0
- package/template/src/features/support/components/user-role-select.tsx +107 -0
- package/template/src/features/support/index.ts +5 -0
- package/template/src/features/support/manifest.ts +53 -0
- package/template/src/features/support/schemas/index.ts +15 -0
- package/template/src/features/support/schemas/ticket.ts +81 -0
- package/template/src/hooks/index.ts +2 -0
- package/template/src/i18n/index.ts +12 -0
- package/template/src/i18n/request.ts +24 -0
- package/template/src/i18n/routing.ts +23 -0
- package/template/src/instrumentation.ts +19 -0
- package/template/src/lib/ai/index.ts +16 -0
- package/template/src/lib/api-logger.ts +24 -0
- package/template/src/lib/auth/admin.ts +54 -0
- package/template/src/lib/auth/api.ts +17 -0
- package/template/src/lib/auth/client.ts +227 -0
- package/template/src/lib/auth/edge.ts +84 -0
- package/template/src/lib/auth/errors.ts +99 -0
- package/template/src/lib/auth/index.ts +159 -0
- package/template/src/lib/auth/server.ts +46 -0
- package/template/src/lib/auth/session-context.tsx +96 -0
- package/template/src/lib/cloudflare/bindings.ts +31 -0
- package/template/src/lib/cookie-consent.ts +33 -0
- package/template/src/lib/file-utils.ts +45 -0
- package/template/src/lib/fingerprint/index.ts +73 -0
- package/template/src/lib/health/checks.ts +6 -0
- package/template/src/lib/health/core.ts +86 -0
- package/template/src/lib/health/index.ts +11 -0
- package/template/src/lib/health/types.ts +13 -0
- package/template/src/lib/index.ts +2 -0
- package/template/src/lib/logger/index.ts +258 -0
- package/template/src/lib/monitoring/index.ts +384 -0
- package/template/src/lib/rate-limit/anonymous.ts +85 -0
- package/template/src/lib/rate-limit/index.ts +111 -0
- package/template/src/lib/safe-action.ts +127 -0
- package/template/src/lib/seo/json-ld.ts +188 -0
- package/template/src/lib/source.ts +122 -0
- package/template/src/lib/utils.ts +6 -0
- package/template/src/middleware.ts +162 -0
- package/template/src/modules/index.ts +10 -0
- package/template/src/modules/presets.ts +8 -0
- package/template/src/modules/registry.ts +34 -0
- package/template/src/modules/selection.ts +45 -0
- package/template/src/services/ai.ts +49 -0
- package/template/src/services/index.ts +6 -0
- package/template/src/services/jobs.ts +3 -0
- package/template/src/services/mail.ts +7 -0
- package/template/src/services/payment.ts +3 -0
- package/template/src/services/rate-limit.ts +12 -0
- package/template/src/services/storage.ts +3 -0
- package/template/src/types/fumadocs-source.d.ts +14 -0
- package/template/src/types/index.ts +2 -0
- package/template/tsconfig.json +53 -0
- package/template/vercel.json +11 -0
- package/template/vitest.config.ts +51 -0
- package/template/wrangler.jsonc +30 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineModule } from "@/core/modules";
|
|
2
|
+
|
|
3
|
+
export const subscriptionModule = defineModule({
|
|
4
|
+
id: "subscription",
|
|
5
|
+
name: "Subscription",
|
|
6
|
+
description: "订阅状态、计划识别和权益计算",
|
|
7
|
+
kind: "optional",
|
|
8
|
+
dependencies: [],
|
|
9
|
+
routes: [],
|
|
10
|
+
navigation: [],
|
|
11
|
+
translations: ["Subscription"],
|
|
12
|
+
schema: ["subscription"],
|
|
13
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户订阅计划服务
|
|
3
|
+
*
|
|
4
|
+
* 提供获取用户当前计划和检查特权的功能
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { eq } from "drizzle-orm";
|
|
8
|
+
import {
|
|
9
|
+
formatFileSizeLimit,
|
|
10
|
+
getPlanFromPriceId,
|
|
11
|
+
getPlanPrivileges,
|
|
12
|
+
getUpgradeMessage,
|
|
13
|
+
isWithinFileSizeLimit,
|
|
14
|
+
type SubscriptionPlan,
|
|
15
|
+
} from "@/config/subscription-plan";
|
|
16
|
+
import { db } from "@/db";
|
|
17
|
+
import { subscription } from "@/db/schema/subscription";
|
|
18
|
+
|
|
19
|
+
// ============================================
|
|
20
|
+
// 类型定义
|
|
21
|
+
// ============================================
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 用户计划信息
|
|
25
|
+
*/
|
|
26
|
+
export interface UserPlanInfo {
|
|
27
|
+
/** 当前计划 */
|
|
28
|
+
plan: SubscriptionPlan;
|
|
29
|
+
/** 计划名称 */
|
|
30
|
+
planName: string;
|
|
31
|
+
/** 是否有活跃订阅 */
|
|
32
|
+
hasActiveSubscription: boolean;
|
|
33
|
+
/** 订阅状态 */
|
|
34
|
+
subscriptionStatus: string | null;
|
|
35
|
+
/** 当前周期结束时间(续期日期) */
|
|
36
|
+
currentPeriodEnd: Date | null;
|
|
37
|
+
/** 价格 ID(用于查找价格信息) */
|
|
38
|
+
priceId: string | null;
|
|
39
|
+
/** 是否在周期结束时取消 */
|
|
40
|
+
cancelAtPeriodEnd: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 特权检查结果
|
|
45
|
+
*/
|
|
46
|
+
export interface PrivilegeCheckResult {
|
|
47
|
+
/** 是否允许 */
|
|
48
|
+
allowed: boolean;
|
|
49
|
+
/** 错误消息(如果不允许) */
|
|
50
|
+
errorMessage?: string;
|
|
51
|
+
/** 升级建议(如果不允许) */
|
|
52
|
+
upgradeMessage?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ============================================
|
|
56
|
+
// 核心服务函数
|
|
57
|
+
// ============================================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 获取用户当前订阅计划
|
|
61
|
+
*
|
|
62
|
+
* 从 subscription 表查询 priceId 并映射到计划类型
|
|
63
|
+
* 如果没有活跃订阅,返回 "free"
|
|
64
|
+
*
|
|
65
|
+
* @param userId - 用户 ID
|
|
66
|
+
* @returns 用户计划信息
|
|
67
|
+
*/
|
|
68
|
+
export async function getUserPlan(userId: string): Promise<UserPlanInfo> {
|
|
69
|
+
// 查询用户的活跃订阅
|
|
70
|
+
const [userSubscription] = await db
|
|
71
|
+
.select({
|
|
72
|
+
priceId: subscription.priceId,
|
|
73
|
+
status: subscription.status,
|
|
74
|
+
currentPeriodEnd: subscription.currentPeriodEnd,
|
|
75
|
+
cancelAtPeriodEnd: subscription.cancelAtPeriodEnd,
|
|
76
|
+
})
|
|
77
|
+
.from(subscription)
|
|
78
|
+
.where(eq(subscription.userId, userId))
|
|
79
|
+
.limit(1);
|
|
80
|
+
|
|
81
|
+
// 检查订阅是否有效
|
|
82
|
+
const isCanceledButStillActive =
|
|
83
|
+
userSubscription?.status === "canceled" &&
|
|
84
|
+
userSubscription.currentPeriodEnd &&
|
|
85
|
+
new Date(userSubscription.currentPeriodEnd) > new Date();
|
|
86
|
+
|
|
87
|
+
const isActive =
|
|
88
|
+
userSubscription &&
|
|
89
|
+
(["active", "trialing", "lifetime"].includes(userSubscription.status) ||
|
|
90
|
+
isCanceledButStillActive);
|
|
91
|
+
|
|
92
|
+
if (!isActive || !userSubscription) {
|
|
93
|
+
return {
|
|
94
|
+
plan: "free",
|
|
95
|
+
planName: "Free",
|
|
96
|
+
hasActiveSubscription: false,
|
|
97
|
+
subscriptionStatus: userSubscription?.status ?? null,
|
|
98
|
+
currentPeriodEnd: null,
|
|
99
|
+
priceId: null,
|
|
100
|
+
cancelAtPeriodEnd: false,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 判断是否处于"已取消待到期"状态
|
|
105
|
+
const effectiveCancelAtPeriodEnd =
|
|
106
|
+
isCanceledButStillActive || userSubscription.cancelAtPeriodEnd;
|
|
107
|
+
|
|
108
|
+
// 从 priceId 映射到计划
|
|
109
|
+
const plan = getPlanFromPriceId(userSubscription.priceId);
|
|
110
|
+
|
|
111
|
+
if (!plan) {
|
|
112
|
+
console.warn(
|
|
113
|
+
`Unknown priceId: ${userSubscription.priceId} for user ${userId}`
|
|
114
|
+
);
|
|
115
|
+
return {
|
|
116
|
+
plan: "free",
|
|
117
|
+
planName: "Free",
|
|
118
|
+
hasActiveSubscription: true,
|
|
119
|
+
subscriptionStatus: userSubscription.status,
|
|
120
|
+
currentPeriodEnd: userSubscription.currentPeriodEnd,
|
|
121
|
+
priceId: userSubscription.priceId,
|
|
122
|
+
cancelAtPeriodEnd: effectiveCancelAtPeriodEnd,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const privileges = getPlanPrivileges(plan);
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
plan,
|
|
130
|
+
planName: privileges.name,
|
|
131
|
+
hasActiveSubscription: true,
|
|
132
|
+
subscriptionStatus: userSubscription.status,
|
|
133
|
+
currentPeriodEnd: userSubscription.currentPeriodEnd,
|
|
134
|
+
priceId: userSubscription.priceId,
|
|
135
|
+
cancelAtPeriodEnd: effectiveCancelAtPeriodEnd,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 获取用户计划类型(简化版,仅返回计划类型)
|
|
141
|
+
*
|
|
142
|
+
* @param userId - 用户 ID
|
|
143
|
+
* @returns 计划类型
|
|
144
|
+
*/
|
|
145
|
+
export async function getUserPlanType(
|
|
146
|
+
userId: string
|
|
147
|
+
): Promise<SubscriptionPlan> {
|
|
148
|
+
const { plan } = await getUserPlan(userId);
|
|
149
|
+
return plan;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ============================================
|
|
153
|
+
// 特权检查函数
|
|
154
|
+
// ============================================
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 检查文件大小是否在用户计划限制内
|
|
158
|
+
*
|
|
159
|
+
* @param userId - 用户 ID
|
|
160
|
+
* @param fileSizeBytes - 文件大小(字节)
|
|
161
|
+
* @returns 检查结果
|
|
162
|
+
*/
|
|
163
|
+
export async function checkFileSizePrivilege(
|
|
164
|
+
userId: string,
|
|
165
|
+
fileSizeBytes: number
|
|
166
|
+
): Promise<PrivilegeCheckResult> {
|
|
167
|
+
const { plan } = await getUserPlan(userId);
|
|
168
|
+
|
|
169
|
+
if (isWithinFileSizeLimit(plan, fileSizeBytes)) {
|
|
170
|
+
return { allowed: true };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const limit = formatFileSizeLimit(plan);
|
|
174
|
+
const actualSize = `${(fileSizeBytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
allowed: false,
|
|
178
|
+
errorMessage: `File size (${actualSize}) exceeds ${limit} limit for your plan.`,
|
|
179
|
+
upgradeMessage: getUpgradeMessage(plan, `Files over ${limit}`),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { desc, eq } from "drizzle-orm";
|
|
4
|
+
import { revalidatePath } from "next/cache";
|
|
5
|
+
|
|
6
|
+
import { db } from "@/db";
|
|
7
|
+
import { user } from "@/db/schema/auth";
|
|
8
|
+
import { ticket, ticketMessage } from "@/db/schema/support";
|
|
9
|
+
import {
|
|
10
|
+
addTicketMessageSchema,
|
|
11
|
+
updateTicketStatusSchema,
|
|
12
|
+
} from "@/features/support/schemas";
|
|
13
|
+
import { adminAction } from "@/lib/safe-action";
|
|
14
|
+
|
|
15
|
+
const withAdminTicketAction = (name: string) =>
|
|
16
|
+
adminAction.metadata({ action: `support.admin.${name}` });
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 获取所有工单列表 (管理员)
|
|
20
|
+
*/
|
|
21
|
+
export const getAllTicketsAction = withAdminTicketAction(
|
|
22
|
+
"getAllTickets"
|
|
23
|
+
).action(async () => {
|
|
24
|
+
const tickets = await db
|
|
25
|
+
.select({
|
|
26
|
+
id: ticket.id,
|
|
27
|
+
subject: ticket.subject,
|
|
28
|
+
category: ticket.category,
|
|
29
|
+
priority: ticket.priority,
|
|
30
|
+
status: ticket.status,
|
|
31
|
+
createdAt: ticket.createdAt,
|
|
32
|
+
updatedAt: ticket.updatedAt,
|
|
33
|
+
user: {
|
|
34
|
+
id: user.id,
|
|
35
|
+
name: user.name,
|
|
36
|
+
email: user.email,
|
|
37
|
+
image: user.image,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
.from(ticket)
|
|
41
|
+
.leftJoin(user, eq(ticket.userId, user.id))
|
|
42
|
+
.orderBy(desc(ticket.createdAt));
|
|
43
|
+
|
|
44
|
+
return { tickets };
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 获取工单详情 (管理员)
|
|
49
|
+
*/
|
|
50
|
+
export const getAdminTicketDetailAction = withAdminTicketAction(
|
|
51
|
+
"getAdminTicketDetail"
|
|
52
|
+
)
|
|
53
|
+
.schema(addTicketMessageSchema.pick({ ticketId: true }))
|
|
54
|
+
.action(async ({ parsedInput: { ticketId } }) => {
|
|
55
|
+
const ticketResult = await db
|
|
56
|
+
.select({
|
|
57
|
+
ticket: ticket,
|
|
58
|
+
user: {
|
|
59
|
+
id: user.id,
|
|
60
|
+
name: user.name,
|
|
61
|
+
email: user.email,
|
|
62
|
+
image: user.image,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
.from(ticket)
|
|
66
|
+
.leftJoin(user, eq(ticket.userId, user.id))
|
|
67
|
+
.where(eq(ticket.id, ticketId))
|
|
68
|
+
.limit(1);
|
|
69
|
+
|
|
70
|
+
const result = ticketResult[0];
|
|
71
|
+
if (!result) {
|
|
72
|
+
throw new Error("工单不存在");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const messages = await db
|
|
76
|
+
.select({
|
|
77
|
+
id: ticketMessage.id,
|
|
78
|
+
content: ticketMessage.content,
|
|
79
|
+
isAdminResponse: ticketMessage.isAdminResponse,
|
|
80
|
+
createdAt: ticketMessage.createdAt,
|
|
81
|
+
user: {
|
|
82
|
+
id: user.id,
|
|
83
|
+
name: user.name,
|
|
84
|
+
image: user.image,
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
.from(ticketMessage)
|
|
88
|
+
.leftJoin(user, eq(ticketMessage.userId, user.id))
|
|
89
|
+
.where(eq(ticketMessage.ticketId, ticketId))
|
|
90
|
+
.orderBy(ticketMessage.createdAt);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
ticket: result.ticket,
|
|
94
|
+
ticketUser: result.user,
|
|
95
|
+
messages,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 管理员回复工单
|
|
101
|
+
*/
|
|
102
|
+
export const adminReplyTicketAction = withAdminTicketAction("replyTicket")
|
|
103
|
+
.schema(addTicketMessageSchema)
|
|
104
|
+
.action(async ({ parsedInput: data, ctx }) => {
|
|
105
|
+
const ticketResult = await db
|
|
106
|
+
.select()
|
|
107
|
+
.from(ticket)
|
|
108
|
+
.where(eq(ticket.id, data.ticketId))
|
|
109
|
+
.limit(1);
|
|
110
|
+
|
|
111
|
+
const ticketData = ticketResult[0];
|
|
112
|
+
if (!ticketData) {
|
|
113
|
+
throw new Error("工单不存在");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
await db.insert(ticketMessage).values({
|
|
117
|
+
id: crypto.randomUUID(),
|
|
118
|
+
ticketId: data.ticketId,
|
|
119
|
+
userId: ctx.userId,
|
|
120
|
+
content: data.content,
|
|
121
|
+
isAdminResponse: true,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (ticketData.status === "open") {
|
|
125
|
+
await db
|
|
126
|
+
.update(ticket)
|
|
127
|
+
.set({ status: "in_progress", updatedAt: new Date() })
|
|
128
|
+
.where(eq(ticket.id, data.ticketId));
|
|
129
|
+
} else {
|
|
130
|
+
await db
|
|
131
|
+
.update(ticket)
|
|
132
|
+
.set({ updatedAt: new Date() })
|
|
133
|
+
.where(eq(ticket.id, data.ticketId));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
revalidatePath(`/admin/tickets/${data.ticketId}`);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
message: "回复成功",
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 更新工单状态 (管理员)
|
|
145
|
+
*/
|
|
146
|
+
export const updateTicketStatusAction = withAdminTicketAction(
|
|
147
|
+
"updateTicketStatus"
|
|
148
|
+
)
|
|
149
|
+
.schema(updateTicketStatusSchema)
|
|
150
|
+
.action(async ({ parsedInput: data }) => {
|
|
151
|
+
const ticketResult = await db
|
|
152
|
+
.select()
|
|
153
|
+
.from(ticket)
|
|
154
|
+
.where(eq(ticket.id, data.ticketId))
|
|
155
|
+
.limit(1);
|
|
156
|
+
|
|
157
|
+
if (ticketResult.length === 0) {
|
|
158
|
+
throw new Error("工单不存在");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await db
|
|
162
|
+
.update(ticket)
|
|
163
|
+
.set({ status: data.status, updatedAt: new Date() })
|
|
164
|
+
.where(eq(ticket.id, data.ticketId));
|
|
165
|
+
|
|
166
|
+
revalidatePath(`/admin/tickets/${data.ticketId}`);
|
|
167
|
+
revalidatePath("/admin/tickets");
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
message: "状态更新成功",
|
|
171
|
+
};
|
|
172
|
+
});
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { eq, ilike, or } from "drizzle-orm";
|
|
4
|
+
import { revalidatePath } from "next/cache";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
import { db } from "@/db";
|
|
8
|
+
import { user } from "@/db/schema/auth";
|
|
9
|
+
import { creditsBalance } from "@/db/schema/credits";
|
|
10
|
+
import { subscription } from "@/db/schema/subscription";
|
|
11
|
+
import { CREDITS_EXPIRY_DAYS, grantCredits } from "@/features/credits";
|
|
12
|
+
import { adminAction } from "@/lib/safe-action";
|
|
13
|
+
|
|
14
|
+
const withAdminUsersAction = (name: string) =>
|
|
15
|
+
adminAction.metadata({ action: `support.adminUsers.${name}` });
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 更新用户角色 Schema
|
|
19
|
+
*/
|
|
20
|
+
const updateUserRoleSchema = z.object({
|
|
21
|
+
userId: z.string().min(1, "用户ID不能为空"),
|
|
22
|
+
role: z.enum(["user", "admin"]),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 封禁/解封用户 Schema
|
|
27
|
+
*/
|
|
28
|
+
const banUserSchema = z.object({
|
|
29
|
+
userId: z.string().min(1, "用户ID不能为空"),
|
|
30
|
+
banned: z.boolean(),
|
|
31
|
+
reason: z.string().optional(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 手动充值积分 Schema
|
|
36
|
+
*/
|
|
37
|
+
const grantCreditsSchema = z.object({
|
|
38
|
+
userId: z.string().min(1, "用户ID不能为空"),
|
|
39
|
+
amount: z
|
|
40
|
+
.number()
|
|
41
|
+
.min(1, "积分数量必须大于0")
|
|
42
|
+
.max(100000, "单次最多充值10万积分"),
|
|
43
|
+
reason: z.string().min(1, "请填写充值原因").max(200, "原因最多200字符"),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 搜索用户 Schema
|
|
48
|
+
*/
|
|
49
|
+
const searchUsersSchema = z.object({
|
|
50
|
+
query: z.string().optional(),
|
|
51
|
+
page: z.number().min(1).default(1),
|
|
52
|
+
pageSize: z.number().min(1).max(100).default(20),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取所有用户列表 (管理员) - 增强版
|
|
57
|
+
*
|
|
58
|
+
* 包含积分余额和订阅状态
|
|
59
|
+
*/
|
|
60
|
+
export const getAllUsersAction = withAdminUsersAction("getAllUsers")
|
|
61
|
+
.schema(searchUsersSchema.optional())
|
|
62
|
+
.action(async ({ parsedInput }) => {
|
|
63
|
+
const query = parsedInput?.query;
|
|
64
|
+
|
|
65
|
+
// 构建用户选择字段
|
|
66
|
+
const userSelectFields = {
|
|
67
|
+
id: user.id,
|
|
68
|
+
name: user.name,
|
|
69
|
+
email: user.email,
|
|
70
|
+
image: user.image,
|
|
71
|
+
role: user.role,
|
|
72
|
+
banned: user.banned,
|
|
73
|
+
bannedReason: user.bannedReason,
|
|
74
|
+
emailVerified: user.emailVerified,
|
|
75
|
+
createdAt: user.createdAt,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// 根据是否有搜索条件构建查询
|
|
79
|
+
const users = query?.trim()
|
|
80
|
+
? await db
|
|
81
|
+
.select(userSelectFields)
|
|
82
|
+
.from(user)
|
|
83
|
+
.where(
|
|
84
|
+
or(
|
|
85
|
+
ilike(user.email, `%${query.trim()}%`),
|
|
86
|
+
ilike(user.name, `%${query.trim()}%`)
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
.orderBy(user.createdAt)
|
|
90
|
+
: await db.select(userSelectFields).from(user).orderBy(user.createdAt);
|
|
91
|
+
|
|
92
|
+
// 获取所有用户的积分余额
|
|
93
|
+
const balances = await db
|
|
94
|
+
.select({
|
|
95
|
+
userId: creditsBalance.userId,
|
|
96
|
+
balance: creditsBalance.balance,
|
|
97
|
+
totalEarned: creditsBalance.totalEarned,
|
|
98
|
+
totalSpent: creditsBalance.totalSpent,
|
|
99
|
+
status: creditsBalance.status,
|
|
100
|
+
})
|
|
101
|
+
.from(creditsBalance);
|
|
102
|
+
|
|
103
|
+
// 获取所有用户的订阅状态
|
|
104
|
+
const subscriptions = await db
|
|
105
|
+
.select({
|
|
106
|
+
userId: subscription.userId,
|
|
107
|
+
status: subscription.status,
|
|
108
|
+
priceId: subscription.priceId,
|
|
109
|
+
currentPeriodEnd: subscription.currentPeriodEnd,
|
|
110
|
+
})
|
|
111
|
+
.from(subscription);
|
|
112
|
+
|
|
113
|
+
// 创建映射
|
|
114
|
+
const balanceMap = new Map(balances.map((b) => [b.userId, b]));
|
|
115
|
+
const subscriptionMap = new Map(subscriptions.map((s) => [s.userId, s]));
|
|
116
|
+
|
|
117
|
+
// 合并数据
|
|
118
|
+
const usersWithDetails = users.map((u) => ({
|
|
119
|
+
...u,
|
|
120
|
+
credits: balanceMap.get(u.id) || null,
|
|
121
|
+
subscription: subscriptionMap.get(u.id) || null,
|
|
122
|
+
}));
|
|
123
|
+
|
|
124
|
+
return { users: usersWithDetails };
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 更新用户角色 (管理员)
|
|
129
|
+
*/
|
|
130
|
+
export const updateUserRoleAction = withAdminUsersAction("updateUserRole")
|
|
131
|
+
.schema(updateUserRoleSchema)
|
|
132
|
+
.action(async ({ parsedInput: data, ctx }) => {
|
|
133
|
+
// 防止管理员更改自己的角色
|
|
134
|
+
if (data.userId === ctx.userId) {
|
|
135
|
+
throw new Error("不能更改自己的角色");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 验证用户存在
|
|
139
|
+
const userResult = await db
|
|
140
|
+
.select()
|
|
141
|
+
.from(user)
|
|
142
|
+
.where(eq(user.id, data.userId))
|
|
143
|
+
.limit(1);
|
|
144
|
+
|
|
145
|
+
if (userResult.length === 0) {
|
|
146
|
+
throw new Error("用户不存在");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 更新角色
|
|
150
|
+
await db
|
|
151
|
+
.update(user)
|
|
152
|
+
.set({ role: data.role, updatedAt: new Date() })
|
|
153
|
+
.where(eq(user.id, data.userId));
|
|
154
|
+
|
|
155
|
+
// 刷新缓存
|
|
156
|
+
revalidatePath("/admin/users");
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
message: `用户角色已更新为 ${data.role === "admin" ? "管理员" : "普通用户"}`,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 封禁/解封用户 (管理员)
|
|
165
|
+
*/
|
|
166
|
+
export const banUserAction = withAdminUsersAction("banUser")
|
|
167
|
+
.schema(banUserSchema)
|
|
168
|
+
.action(async ({ parsedInput: data, ctx }) => {
|
|
169
|
+
// 防止管理员封禁自己
|
|
170
|
+
if (data.userId === ctx.userId) {
|
|
171
|
+
throw new Error("不能封禁自己");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 验证用户存在
|
|
175
|
+
const userResult = await db
|
|
176
|
+
.select()
|
|
177
|
+
.from(user)
|
|
178
|
+
.where(eq(user.id, data.userId))
|
|
179
|
+
.limit(1);
|
|
180
|
+
|
|
181
|
+
if (userResult.length === 0) {
|
|
182
|
+
throw new Error("用户不存在");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 获取目标用户 (经过上面检查,此处一定存在)
|
|
186
|
+
const targetUser = userResult[0]!;
|
|
187
|
+
|
|
188
|
+
// 不能封禁其他管理员
|
|
189
|
+
if (targetUser.role === "admin" && data.banned) {
|
|
190
|
+
throw new Error("不能封禁管理员账户");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 更新封禁状态
|
|
194
|
+
await db
|
|
195
|
+
.update(user)
|
|
196
|
+
.set({
|
|
197
|
+
banned: data.banned,
|
|
198
|
+
bannedReason: data.banned ? data.reason || null : null,
|
|
199
|
+
updatedAt: new Date(),
|
|
200
|
+
})
|
|
201
|
+
.where(eq(user.id, data.userId));
|
|
202
|
+
|
|
203
|
+
// 刷新缓存
|
|
204
|
+
revalidatePath("/admin/users");
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
message: data.banned ? "用户已被封禁" : "用户已解除封禁",
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 手动充值积分 (管理员)
|
|
213
|
+
*/
|
|
214
|
+
export const adminGrantCreditsAction = withAdminUsersAction("grantCredits")
|
|
215
|
+
.schema(grantCreditsSchema)
|
|
216
|
+
.action(async ({ parsedInput: data, ctx }) => {
|
|
217
|
+
// 验证用户存在
|
|
218
|
+
const userResult = await db
|
|
219
|
+
.select()
|
|
220
|
+
.from(user)
|
|
221
|
+
.where(eq(user.id, data.userId))
|
|
222
|
+
.limit(1);
|
|
223
|
+
|
|
224
|
+
if (userResult.length === 0) {
|
|
225
|
+
throw new Error("用户不存在");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 计算过期时间
|
|
229
|
+
const expiresAt = CREDITS_EXPIRY_DAYS
|
|
230
|
+
? new Date(Date.now() + CREDITS_EXPIRY_DAYS * 24 * 60 * 60 * 1000)
|
|
231
|
+
: null;
|
|
232
|
+
|
|
233
|
+
// 调用积分系统发放积分
|
|
234
|
+
const result = await grantCredits({
|
|
235
|
+
userId: data.userId,
|
|
236
|
+
amount: data.amount,
|
|
237
|
+
sourceType: "bonus",
|
|
238
|
+
debitAccount: `ADMIN:${ctx.userId}`,
|
|
239
|
+
transactionType: "admin_grant",
|
|
240
|
+
expiresAt,
|
|
241
|
+
sourceRef: `admin_grant_${Date.now()}`,
|
|
242
|
+
description: `管理员充值: ${data.reason}`,
|
|
243
|
+
metadata: {
|
|
244
|
+
grantType: "admin_manual",
|
|
245
|
+
adminId: ctx.userId,
|
|
246
|
+
reason: data.reason,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// 刷新缓存
|
|
251
|
+
revalidatePath("/admin/users");
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
message: `成功为用户充值 ${data.amount} 积分`,
|
|
255
|
+
newBalance: result.newBalance,
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 获取单个用户详情 (管理员)
|
|
261
|
+
*/
|
|
262
|
+
export const getUserDetailAction = withAdminUsersAction("getUserDetail")
|
|
263
|
+
.schema(z.object({ userId: z.string().min(1) }))
|
|
264
|
+
.action(async ({ parsedInput: { userId } }) => {
|
|
265
|
+
// 获取用户基本信息
|
|
266
|
+
const userResult = await db
|
|
267
|
+
.select()
|
|
268
|
+
.from(user)
|
|
269
|
+
.where(eq(user.id, userId))
|
|
270
|
+
.limit(1);
|
|
271
|
+
|
|
272
|
+
if (userResult.length === 0) {
|
|
273
|
+
throw new Error("用户不存在");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// 获取积分余额
|
|
277
|
+
const balanceResult = await db
|
|
278
|
+
.select()
|
|
279
|
+
.from(creditsBalance)
|
|
280
|
+
.where(eq(creditsBalance.userId, userId))
|
|
281
|
+
.limit(1);
|
|
282
|
+
|
|
283
|
+
// 获取订阅状态
|
|
284
|
+
const subscriptionResult = await db
|
|
285
|
+
.select()
|
|
286
|
+
.from(subscription)
|
|
287
|
+
.where(eq(subscription.userId, userId))
|
|
288
|
+
.limit(1);
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
user: userResult[0],
|
|
292
|
+
credits: balanceResult[0] || null,
|
|
293
|
+
subscription: subscriptionResult[0] || null,
|
|
294
|
+
};
|
|
295
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// 工单 Actions 模块导出
|
|
2
|
+
|
|
3
|
+
// 管理员用户管理 Actions
|
|
4
|
+
export {
|
|
5
|
+
adminGrantCreditsAction,
|
|
6
|
+
banUserAction,
|
|
7
|
+
getAllUsersAction,
|
|
8
|
+
getUserDetailAction,
|
|
9
|
+
updateUserRoleAction,
|
|
10
|
+
} from "./admin-users";
|
|
11
|
+
export {
|
|
12
|
+
addTicketMessageAction,
|
|
13
|
+
adminReplyTicketAction,
|
|
14
|
+
// 用户端 Actions
|
|
15
|
+
createTicketAction,
|
|
16
|
+
getAdminTicketDetailAction,
|
|
17
|
+
// 管理员 Actions
|
|
18
|
+
getAllTicketsAction,
|
|
19
|
+
getMyTicketsAction,
|
|
20
|
+
getTicketDetailAction,
|
|
21
|
+
updateTicketStatusAction,
|
|
22
|
+
} from "./ticket";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
adminReplyTicketAction,
|
|
3
|
+
getAdminTicketDetailAction,
|
|
4
|
+
getAllTicketsAction,
|
|
5
|
+
updateTicketStatusAction,
|
|
6
|
+
} from "./admin-ticket";
|
|
7
|
+
export {
|
|
8
|
+
addTicketMessageAction,
|
|
9
|
+
createTicketAction,
|
|
10
|
+
getMyTicketsAction,
|
|
11
|
+
getTicketDetailAction,
|
|
12
|
+
} from "./user-ticket";
|