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,341 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ChevronsUpDown, LogOut, Settings } from "lucide-react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { usePathname, useRouter } from "next/navigation";
|
|
6
|
+
import { useTranslations } from "next-intl";
|
|
7
|
+
import { type ReactNode, useState } from "react";
|
|
8
|
+
|
|
9
|
+
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
10
|
+
import {
|
|
11
|
+
Popover,
|
|
12
|
+
PopoverContent,
|
|
13
|
+
PopoverTrigger,
|
|
14
|
+
} from "@/components/ui/popover";
|
|
15
|
+
import { Separator } from "@/components/ui/separator";
|
|
16
|
+
import { Sheet, SheetContent, SheetTitle } from "@/components/ui/sheet";
|
|
17
|
+
import { dashboardConfig } from "@/config";
|
|
18
|
+
import { useSidebar } from "@/features/dashboard/context";
|
|
19
|
+
import { ModeToggle } from "@/features/shared";
|
|
20
|
+
import { signOut, useSession } from "@/lib/auth/client";
|
|
21
|
+
import { cn } from "@/lib/utils";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Dashboard 侧边栏组件
|
|
25
|
+
*
|
|
26
|
+
* 功能:
|
|
27
|
+
* - 导航菜单 (从配置读取)
|
|
28
|
+
* - 用户信息弹出菜单
|
|
29
|
+
* - 主题切换
|
|
30
|
+
* - 设置入口
|
|
31
|
+
* - 登出功能
|
|
32
|
+
* - 支持折叠/展开
|
|
33
|
+
*/
|
|
34
|
+
export function DashboardSidebar({
|
|
35
|
+
compactAccountBadge,
|
|
36
|
+
accountPlanBadge,
|
|
37
|
+
}: {
|
|
38
|
+
compactAccountBadge?: ReactNode;
|
|
39
|
+
accountPlanBadge?: ReactNode;
|
|
40
|
+
}) {
|
|
41
|
+
const pathname = usePathname();
|
|
42
|
+
const router = useRouter();
|
|
43
|
+
const { isCollapsed, isMobileOpen, setMobileOpen, toggleSidebar } =
|
|
44
|
+
useSidebar();
|
|
45
|
+
const t = useTranslations("Dashboard");
|
|
46
|
+
|
|
47
|
+
// 获取当前用户会话
|
|
48
|
+
const { data: session } = useSession();
|
|
49
|
+
const user = session?.user;
|
|
50
|
+
|
|
51
|
+
// Popover 开关状态
|
|
52
|
+
const [open, setOpen] = useState(false);
|
|
53
|
+
|
|
54
|
+
const getNavTitle = (title: string, translationKey?: string) =>
|
|
55
|
+
translationKey ? t(translationKey) : title;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 获取用户名首字母作为头像回退
|
|
59
|
+
*/
|
|
60
|
+
const getInitials = (name: string) => {
|
|
61
|
+
return name
|
|
62
|
+
.split(" ")
|
|
63
|
+
.map((n) => n[0])
|
|
64
|
+
.join("")
|
|
65
|
+
.toUpperCase()
|
|
66
|
+
.slice(0, 2);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 处理登出
|
|
71
|
+
*/
|
|
72
|
+
const handleSignOut = async () => {
|
|
73
|
+
setOpen(false);
|
|
74
|
+
await signOut({
|
|
75
|
+
fetchOptions: {
|
|
76
|
+
onSuccess: () => {
|
|
77
|
+
router.push("/");
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 处理设置点击
|
|
85
|
+
*/
|
|
86
|
+
const handleSettingsClick = () => {
|
|
87
|
+
setOpen(false);
|
|
88
|
+
router.push("/dashboard/settings");
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 渲染侧边栏内容(桌面和移动端共用)
|
|
93
|
+
* mobile 参数控制是否为移动端模式(始终展开,点击关闭)
|
|
94
|
+
*/
|
|
95
|
+
const renderSidebarContent = (mobile: boolean) => {
|
|
96
|
+
const collapsed = mobile ? false : isCollapsed;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
{/* Logo */}
|
|
101
|
+
<div className="flex h-14 items-center px-4">
|
|
102
|
+
<Link
|
|
103
|
+
href="/"
|
|
104
|
+
className="flex items-center gap-2"
|
|
105
|
+
onClick={(e) => {
|
|
106
|
+
if (mobile) {
|
|
107
|
+
setMobileOpen(false);
|
|
108
|
+
} else if (collapsed) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
toggleSidebar();
|
|
111
|
+
}
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{/* biome-ignore lint/a11y/noSvgWithoutTitle: decorative logo */}
|
|
115
|
+
<svg
|
|
116
|
+
className="h-6 w-6 shrink-0 text-primary"
|
|
117
|
+
viewBox="0 0 24 24"
|
|
118
|
+
fill="none"
|
|
119
|
+
stroke="currentColor"
|
|
120
|
+
strokeWidth={2.4}
|
|
121
|
+
strokeLinecap="round"
|
|
122
|
+
strokeLinejoin="round"
|
|
123
|
+
>
|
|
124
|
+
<path d="M3 17 L9 7 L13 14 L21 4" />
|
|
125
|
+
<circle cx="9" cy="7" r="1.4" fill="currentColor" stroke="none" />
|
|
126
|
+
<circle
|
|
127
|
+
cx="21"
|
|
128
|
+
cy="4"
|
|
129
|
+
r="1.4"
|
|
130
|
+
fill="currentColor"
|
|
131
|
+
stroke="none"
|
|
132
|
+
/>
|
|
133
|
+
</svg>
|
|
134
|
+
<span
|
|
135
|
+
className={cn(
|
|
136
|
+
"text-lg font-bold tracking-tight transition-opacity",
|
|
137
|
+
collapsed && "opacity-0"
|
|
138
|
+
)}
|
|
139
|
+
>
|
|
140
|
+
NextDev<span className="text-muted-foreground">Tpl</span>
|
|
141
|
+
</span>
|
|
142
|
+
</Link>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
{/* 导航菜单 */}
|
|
146
|
+
<nav className="flex-1 space-y-4 overflow-y-auto p-3">
|
|
147
|
+
{dashboardConfig.sidebarNav.map((group) => (
|
|
148
|
+
<div key={group.title}>
|
|
149
|
+
{/* Group Label - 折叠时隐藏 */}
|
|
150
|
+
{!collapsed && (
|
|
151
|
+
<p className="mb-1.5 px-2 text-xs font-medium uppercase tracking-wider text-muted-foreground">
|
|
152
|
+
{getNavTitle(group.title, group.translationKey)}
|
|
153
|
+
</p>
|
|
154
|
+
)}
|
|
155
|
+
<div className="space-y-0.5">
|
|
156
|
+
{group.items.map((item) => {
|
|
157
|
+
// 去掉 locale 前缀后比较路径
|
|
158
|
+
const normalizedPath = pathname.replace(/^\/[a-z]{2}\//, "/");
|
|
159
|
+
const isActive =
|
|
160
|
+
normalizedPath === item.href ||
|
|
161
|
+
(item.href !== "/dashboard" &&
|
|
162
|
+
normalizedPath.startsWith(`${item.href}/`));
|
|
163
|
+
const Icon = item.icon;
|
|
164
|
+
const translatedTitle = getNavTitle(
|
|
165
|
+
item.title,
|
|
166
|
+
item.translationKey
|
|
167
|
+
);
|
|
168
|
+
return (
|
|
169
|
+
<Link
|
|
170
|
+
key={item.href}
|
|
171
|
+
href={item.href}
|
|
172
|
+
title={collapsed ? translatedTitle : undefined}
|
|
173
|
+
onClick={() => mobile && setMobileOpen(false)}
|
|
174
|
+
className={cn(
|
|
175
|
+
"flex items-center gap-3 rounded-md px-2 py-1.5 text-sm font-medium transition-colors",
|
|
176
|
+
isActive
|
|
177
|
+
? "bg-primary/10 text-primary"
|
|
178
|
+
: "text-sidebar-foreground/70 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground",
|
|
179
|
+
collapsed && "justify-center px-0"
|
|
180
|
+
)}
|
|
181
|
+
>
|
|
182
|
+
{Icon && <Icon className="h-4 w-4 shrink-0" />}
|
|
183
|
+
{!collapsed && (
|
|
184
|
+
<span className="flex-1">{translatedTitle}</span>
|
|
185
|
+
)}
|
|
186
|
+
</Link>
|
|
187
|
+
);
|
|
188
|
+
})}
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
))}
|
|
192
|
+
</nav>
|
|
193
|
+
|
|
194
|
+
{/* 用户信息区域 */}
|
|
195
|
+
<div className="border-t border-sidebar-border p-3">
|
|
196
|
+
{user ? (
|
|
197
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
198
|
+
<PopoverTrigger asChild>
|
|
199
|
+
<button
|
|
200
|
+
type="button"
|
|
201
|
+
className={cn(
|
|
202
|
+
"flex w-full items-center gap-3 rounded-md px-2 py-1.5 hover:bg-sidebar-accent/50 transition-colors",
|
|
203
|
+
collapsed && "justify-center px-0"
|
|
204
|
+
)}
|
|
205
|
+
>
|
|
206
|
+
<Avatar className="h-8 w-8 shrink-0">
|
|
207
|
+
<AvatarImage
|
|
208
|
+
src={user.image || undefined}
|
|
209
|
+
alt={user.name}
|
|
210
|
+
/>
|
|
211
|
+
<AvatarFallback className="bg-primary text-primary-foreground text-xs">
|
|
212
|
+
{getInitials(user.name)}
|
|
213
|
+
</AvatarFallback>
|
|
214
|
+
</Avatar>
|
|
215
|
+
{!collapsed && (
|
|
216
|
+
<>
|
|
217
|
+
<div className="flex-1 truncate text-left">
|
|
218
|
+
<div className="flex items-center gap-2">
|
|
219
|
+
<p className="text-sm font-medium">{user.name}</p>
|
|
220
|
+
{compactAccountBadge}
|
|
221
|
+
</div>
|
|
222
|
+
<p className="truncate text-xs text-muted-foreground">
|
|
223
|
+
{user.email}
|
|
224
|
+
</p>
|
|
225
|
+
</div>
|
|
226
|
+
<ChevronsUpDown className="h-4 w-4 text-muted-foreground" />
|
|
227
|
+
</>
|
|
228
|
+
)}
|
|
229
|
+
</button>
|
|
230
|
+
</PopoverTrigger>
|
|
231
|
+
|
|
232
|
+
<PopoverContent
|
|
233
|
+
side="top"
|
|
234
|
+
align="start"
|
|
235
|
+
sideOffset={8}
|
|
236
|
+
className="w-64 p-0"
|
|
237
|
+
>
|
|
238
|
+
{/* 用户信息头部 */}
|
|
239
|
+
<div className="flex items-center gap-3 p-4">
|
|
240
|
+
<Avatar className="h-10 w-10">
|
|
241
|
+
<AvatarImage
|
|
242
|
+
src={user.image || undefined}
|
|
243
|
+
alt={user.name}
|
|
244
|
+
/>
|
|
245
|
+
<AvatarFallback className="bg-primary text-primary-foreground">
|
|
246
|
+
{getInitials(user.name)}
|
|
247
|
+
</AvatarFallback>
|
|
248
|
+
</Avatar>
|
|
249
|
+
<div className="flex-1 truncate">
|
|
250
|
+
<div className="flex items-center gap-2">
|
|
251
|
+
<p className="font-medium">{user.name}</p>
|
|
252
|
+
{accountPlanBadge}
|
|
253
|
+
</div>
|
|
254
|
+
<p className="truncate text-sm text-muted-foreground">
|
|
255
|
+
{user.email}
|
|
256
|
+
</p>
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
<Separator />
|
|
261
|
+
|
|
262
|
+
{/* 主题切换 - 使用共享 ModeToggle 组件 */}
|
|
263
|
+
<div className="flex items-center justify-center p-3">
|
|
264
|
+
<ModeToggle variant="inline" />
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
<Separator />
|
|
268
|
+
|
|
269
|
+
{/* 菜单项 */}
|
|
270
|
+
<div className="p-2">
|
|
271
|
+
{/* 设置 */}
|
|
272
|
+
<button
|
|
273
|
+
type="button"
|
|
274
|
+
onClick={handleSettingsClick}
|
|
275
|
+
className="flex w-full items-center gap-3 rounded-md px-3 py-2 text-sm hover:bg-muted transition-colors"
|
|
276
|
+
>
|
|
277
|
+
<Settings className="h-4 w-4" />
|
|
278
|
+
{t("sidebar.settings")}
|
|
279
|
+
</button>
|
|
280
|
+
|
|
281
|
+
{/* 登出 */}
|
|
282
|
+
<button
|
|
283
|
+
type="button"
|
|
284
|
+
onClick={handleSignOut}
|
|
285
|
+
className="flex w-full items-center gap-3 rounded-md px-3 py-2 text-sm hover:bg-muted transition-colors"
|
|
286
|
+
>
|
|
287
|
+
<LogOut className="h-4 w-4" />
|
|
288
|
+
{t("sidebar.logout")}
|
|
289
|
+
</button>
|
|
290
|
+
</div>
|
|
291
|
+
</PopoverContent>
|
|
292
|
+
</Popover>
|
|
293
|
+
) : (
|
|
294
|
+
// 加载状态
|
|
295
|
+
<div
|
|
296
|
+
className={cn(
|
|
297
|
+
"flex items-center gap-3 rounded-md px-2 py-1.5",
|
|
298
|
+
collapsed && "justify-center px-0"
|
|
299
|
+
)}
|
|
300
|
+
>
|
|
301
|
+
<div className="h-8 w-8 animate-pulse rounded-full bg-sidebar-accent shrink-0" />
|
|
302
|
+
{!collapsed && (
|
|
303
|
+
<div className="flex-1 space-y-1">
|
|
304
|
+
<div className="h-4 w-20 animate-pulse rounded bg-sidebar-accent" />
|
|
305
|
+
<div className="h-3 w-32 animate-pulse rounded bg-sidebar-accent" />
|
|
306
|
+
</div>
|
|
307
|
+
)}
|
|
308
|
+
</div>
|
|
309
|
+
)}
|
|
310
|
+
</div>
|
|
311
|
+
</>
|
|
312
|
+
);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<>
|
|
317
|
+
{/* 桌面端侧边栏 */}
|
|
318
|
+
<aside
|
|
319
|
+
className={cn(
|
|
320
|
+
"fixed left-0 top-0 z-40 hidden h-screen flex-col bg-sidebar border-r border-sidebar-border transition-all duration-300 md:flex",
|
|
321
|
+
isCollapsed ? "w-16" : "w-64"
|
|
322
|
+
)}
|
|
323
|
+
>
|
|
324
|
+
{renderSidebarContent(false)}
|
|
325
|
+
</aside>
|
|
326
|
+
|
|
327
|
+
{/* 移动端 Sheet 侧边栏 */}
|
|
328
|
+
<Sheet open={isMobileOpen} onOpenChange={setMobileOpen}>
|
|
329
|
+
<SheetContent
|
|
330
|
+
side="left"
|
|
331
|
+
className="w-64 bg-sidebar p-0 md:hidden [&>button:last-child]:hidden"
|
|
332
|
+
>
|
|
333
|
+
<SheetTitle className="sr-only">Navigation</SheetTitle>
|
|
334
|
+
<div className="flex h-full flex-col">
|
|
335
|
+
{renderSidebarContent(true)}
|
|
336
|
+
</div>
|
|
337
|
+
</SheetContent>
|
|
338
|
+
</Sheet>
|
|
339
|
+
</>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useCallback, useContext, useState } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 侧边栏上下文类型
|
|
7
|
+
*/
|
|
8
|
+
interface SidebarContextType {
|
|
9
|
+
/** 侧边栏是否折叠 */
|
|
10
|
+
isCollapsed: boolean;
|
|
11
|
+
/** 切换折叠状态 */
|
|
12
|
+
toggleSidebar: () => void;
|
|
13
|
+
/** 设置折叠状态 */
|
|
14
|
+
setCollapsed: (collapsed: boolean) => void;
|
|
15
|
+
/** 移动端侧边栏是否打开 */
|
|
16
|
+
isMobileOpen: boolean;
|
|
17
|
+
/** 设置移动端侧边栏状态 */
|
|
18
|
+
setMobileOpen: (open: boolean) => void;
|
|
19
|
+
/** 切换移动端侧边栏 */
|
|
20
|
+
toggleMobile: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 侧边栏上下文
|
|
25
|
+
*/
|
|
26
|
+
const SidebarContext = createContext<SidebarContextType | undefined>(undefined);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 侧边栏上下文提供者
|
|
30
|
+
*/
|
|
31
|
+
export function SidebarProvider({ children }: { children: React.ReactNode }) {
|
|
32
|
+
const [isCollapsed, setIsCollapsed] = useState(false);
|
|
33
|
+
const [isMobileOpen, setMobileOpen] = useState(false);
|
|
34
|
+
|
|
35
|
+
const toggleSidebar = useCallback(() => {
|
|
36
|
+
setIsCollapsed((prev) => !prev);
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
39
|
+
const setCollapsed = useCallback((collapsed: boolean) => {
|
|
40
|
+
setIsCollapsed(collapsed);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
const toggleMobile = useCallback(() => {
|
|
44
|
+
setMobileOpen((prev) => !prev);
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<SidebarContext.Provider
|
|
49
|
+
value={{
|
|
50
|
+
isCollapsed,
|
|
51
|
+
toggleSidebar,
|
|
52
|
+
setCollapsed,
|
|
53
|
+
isMobileOpen,
|
|
54
|
+
setMobileOpen,
|
|
55
|
+
toggleMobile,
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
</SidebarContext.Provider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 使用侧边栏上下文的 Hook
|
|
65
|
+
*/
|
|
66
|
+
export function useSidebar() {
|
|
67
|
+
const context = useContext(SidebarContext);
|
|
68
|
+
if (!context) {
|
|
69
|
+
throw new Error("useSidebar must be used within a SidebarProvider");
|
|
70
|
+
}
|
|
71
|
+
return context;
|
|
72
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineModule } from "@/core/modules";
|
|
2
|
+
|
|
3
|
+
export const dashboardModule = defineModule({
|
|
4
|
+
id: "dashboard",
|
|
5
|
+
name: "Dashboard",
|
|
6
|
+
description: "登录后的基础工作区与侧边栏框架",
|
|
7
|
+
kind: "core",
|
|
8
|
+
dependencies: ["shared"],
|
|
9
|
+
routes: [
|
|
10
|
+
{
|
|
11
|
+
path: "/dashboard",
|
|
12
|
+
source: "src/app/[locale]/(dashboard)/dashboard/page.tsx",
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
navigation: [
|
|
16
|
+
{
|
|
17
|
+
area: "dashboard",
|
|
18
|
+
group: "dashboard",
|
|
19
|
+
groupTranslationKey: "nav.dashboard",
|
|
20
|
+
translationKey: "nav.dashboard",
|
|
21
|
+
href: "/dashboard",
|
|
22
|
+
icon: "dashboard",
|
|
23
|
+
order: 10,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
translations: ["Dashboard", "DashboardPages"],
|
|
27
|
+
schema: [],
|
|
28
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 邮件系统 Server Actions
|
|
5
|
+
*
|
|
6
|
+
* 提供邮件相关的服务端操作接口
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { eq } from "drizzle-orm";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
import { db } from "@/db";
|
|
13
|
+
import { newsletterSubscriber } from "@/db/schema/mail";
|
|
14
|
+
import { actionClient } from "@/lib/safe-action";
|
|
15
|
+
|
|
16
|
+
const withMailAction = (name: string) =>
|
|
17
|
+
actionClient.metadata({ action: `mail.${name}` });
|
|
18
|
+
|
|
19
|
+
// ============================================
|
|
20
|
+
// Newsletter 订阅 Actions
|
|
21
|
+
// ============================================
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 订阅 Newsletter
|
|
25
|
+
*
|
|
26
|
+
* 公开 Action - 任何人都可以订阅
|
|
27
|
+
* 如果邮箱已存在但取消订阅过,会重新激活订阅
|
|
28
|
+
*/
|
|
29
|
+
export const subscribeNewsletter = withMailAction("subscribeNewsletter")
|
|
30
|
+
.schema(
|
|
31
|
+
z.object({
|
|
32
|
+
email: z.string().email("请输入有效的邮箱地址"),
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
.action(async ({ parsedInput }) => {
|
|
36
|
+
const { email } = parsedInput;
|
|
37
|
+
const normalizedEmail = email.toLowerCase().trim();
|
|
38
|
+
|
|
39
|
+
// 检查是否已存在
|
|
40
|
+
const [existing] = await db
|
|
41
|
+
.select()
|
|
42
|
+
.from(newsletterSubscriber)
|
|
43
|
+
.where(eq(newsletterSubscriber.email, normalizedEmail))
|
|
44
|
+
.limit(1);
|
|
45
|
+
|
|
46
|
+
if (existing) {
|
|
47
|
+
// 如果已存在且已订阅,返回提示
|
|
48
|
+
if (existing.isSubscribed) {
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
message: "You are already subscribed!",
|
|
52
|
+
alreadySubscribed: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 如果曾经取消过订阅,重新激活
|
|
57
|
+
await db
|
|
58
|
+
.update(newsletterSubscriber)
|
|
59
|
+
.set({
|
|
60
|
+
isSubscribed: true,
|
|
61
|
+
subscribedAt: new Date(),
|
|
62
|
+
unsubscribedAt: null,
|
|
63
|
+
updatedAt: new Date(),
|
|
64
|
+
})
|
|
65
|
+
.where(eq(newsletterSubscriber.id, existing.id));
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
success: true,
|
|
69
|
+
message: "Welcome back! Your subscription has been reactivated.",
|
|
70
|
+
reactivated: true,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 创建新订阅
|
|
75
|
+
await db.insert(newsletterSubscriber).values({
|
|
76
|
+
id: crypto.randomUUID(),
|
|
77
|
+
email: normalizedEmail,
|
|
78
|
+
isSubscribed: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
success: true,
|
|
83
|
+
message: "Thank you for subscribing!",
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 取消订阅 Newsletter
|
|
89
|
+
*
|
|
90
|
+
* 公开 Action - 通过邮箱取消订阅
|
|
91
|
+
* 不会删除记录,只是标记为未订阅
|
|
92
|
+
*/
|
|
93
|
+
export const unsubscribeNewsletter = withMailAction("unsubscribeNewsletter")
|
|
94
|
+
.schema(
|
|
95
|
+
z.object({
|
|
96
|
+
email: z.string().email("请输入有效的邮箱地址"),
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
.action(async ({ parsedInput }) => {
|
|
100
|
+
const { email } = parsedInput;
|
|
101
|
+
const normalizedEmail = email.toLowerCase().trim();
|
|
102
|
+
|
|
103
|
+
// 查找订阅记录
|
|
104
|
+
const [existing] = await db
|
|
105
|
+
.select()
|
|
106
|
+
.from(newsletterSubscriber)
|
|
107
|
+
.where(eq(newsletterSubscriber.email, normalizedEmail))
|
|
108
|
+
.limit(1);
|
|
109
|
+
|
|
110
|
+
if (!existing) {
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
message: "Email not found in our subscriber list.",
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!existing.isSubscribed) {
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
message: "You are already unsubscribed.",
|
|
121
|
+
alreadyUnsubscribed: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 更新为取消订阅状态
|
|
126
|
+
await db
|
|
127
|
+
.update(newsletterSubscriber)
|
|
128
|
+
.set({
|
|
129
|
+
isSubscribed: false,
|
|
130
|
+
unsubscribedAt: new Date(),
|
|
131
|
+
updatedAt: new Date(),
|
|
132
|
+
})
|
|
133
|
+
.where(eq(newsletterSubscriber.id, existing.id));
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
message: "You have been unsubscribed. We're sorry to see you go!",
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 检查邮箱订阅状态
|
|
143
|
+
*/
|
|
144
|
+
export const checkSubscriptionStatus = withMailAction("checkSubscriptionStatus")
|
|
145
|
+
.schema(
|
|
146
|
+
z.object({
|
|
147
|
+
email: z.string().email(),
|
|
148
|
+
})
|
|
149
|
+
)
|
|
150
|
+
.action(async ({ parsedInput }) => {
|
|
151
|
+
const { email } = parsedInput;
|
|
152
|
+
const normalizedEmail = email.toLowerCase().trim();
|
|
153
|
+
|
|
154
|
+
const [subscriber] = await db
|
|
155
|
+
.select({
|
|
156
|
+
isSubscribed: newsletterSubscriber.isSubscribed,
|
|
157
|
+
subscribedAt: newsletterSubscriber.subscribedAt,
|
|
158
|
+
})
|
|
159
|
+
.from(newsletterSubscriber)
|
|
160
|
+
.where(eq(newsletterSubscriber.email, normalizedEmail))
|
|
161
|
+
.limit(1);
|
|
162
|
+
|
|
163
|
+
if (!subscriber) {
|
|
164
|
+
return {
|
|
165
|
+
found: false,
|
|
166
|
+
isSubscribed: false,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
found: true,
|
|
172
|
+
isSubscribed: subscriber.isSubscribed,
|
|
173
|
+
subscribedAt: subscriber.subscribedAt,
|
|
174
|
+
};
|
|
175
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineModule } from "@/core/modules";
|
|
2
|
+
|
|
3
|
+
export const mailModule = defineModule({
|
|
4
|
+
id: "mail",
|
|
5
|
+
name: "Mail",
|
|
6
|
+
description: "事务邮件、邮件模板和 Newsletter",
|
|
7
|
+
kind: "core",
|
|
8
|
+
dependencies: [],
|
|
9
|
+
routes: [],
|
|
10
|
+
navigation: [],
|
|
11
|
+
translations: [],
|
|
12
|
+
schema: ["mail"],
|
|
13
|
+
});
|