create-ej-app 26.0.0 → 28.0.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 +125 -226
- package/cli.ts +79 -29
- package/package.json +2 -2
- package/template/api/.vscode/settings.json +1 -1
- package/template/api/{.github/copilot-instructions.md → AGENTS.md} +0 -2
- package/template/api/CLAUDE.md +1 -0
- package/template/api/package.json +10 -10
- package/template/nextjs/.dockerignore +1 -0
- package/template/nextjs/AGENTS.md +260 -0
- package/template/nextjs/CLAUDE.md +1 -0
- package/template/nextjs/README.md +109 -0
- package/template/nextjs/bunfig.toml +3 -0
- package/template/nextjs/eslint.config.mjs +6 -5
- package/template/nextjs/gitignore +6 -1
- package/template/nextjs/next.config.ts +8 -1
- package/template/nextjs/package.json +47 -39
- package/template/nextjs/public/logo-dark.svg +4 -0
- package/template/nextjs/public/logo.svg +4 -0
- package/template/nextjs/src/app/(admin)/actions/users.ts +183 -0
- package/template/nextjs/src/app/(admin)/admin/_components/admin-header.tsx +24 -0
- package/template/nextjs/src/app/(admin)/admin/_components/admin-search.tsx +16 -0
- package/template/nextjs/src/app/(admin)/admin/_components/admin-sidebar.tsx +42 -0
- package/template/nextjs/src/app/(admin)/admin/layout.tsx +53 -0
- package/template/nextjs/src/app/(admin)/admin/page.tsx +11 -2
- package/template/nextjs/src/app/(admin)/admin/settings/layout.tsx +24 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/[userId]/page.tsx +43 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/new/page.tsx +16 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/page.tsx +377 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/user-form.tsx +138 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/validation.ts +23 -0
- package/template/nextjs/src/app/(app)/app/layout.tsx +44 -0
- package/template/nextjs/src/app/(app)/app/page.tsx +14 -2
- package/template/nextjs/src/app/(auth)/(account)/layout.tsx +64 -0
- package/template/nextjs/src/app/(auth)/(account)/profile/page.tsx +16 -0
- package/template/nextjs/src/app/(auth)/(account)/profile/profile-form.tsx +247 -0
- package/template/nextjs/src/app/(auth)/login/email-login-form.tsx +56 -29
- package/template/nextjs/src/app/(auth)/login/page.tsx +45 -12
- package/template/nextjs/src/app/(auth)/login/social-login-buttons.tsx +85 -17
- package/template/nextjs/src/app/(marketing)/layout.tsx +35 -4
- package/template/nextjs/src/app/(marketing)/legal.tsx +56 -0
- package/template/nextjs/src/app/(marketing)/page.tsx +20 -2
- package/template/nextjs/src/app/(marketing)/privacy/page.tsx +43 -2
- package/template/nextjs/src/app/(marketing)/terms/page.tsx +33 -2
- package/template/nextjs/src/app/error.tsx +37 -0
- package/template/nextjs/src/app/fonts/geist-mono/GeistMono-Variable.woff2 +0 -0
- package/template/nextjs/src/app/fonts/geist-sans/Geist-Variable.woff2 +0 -0
- package/template/nextjs/src/app/fonts/index.ts +60 -0
- package/template/nextjs/src/app/global-error.tsx +38 -0
- package/template/nextjs/src/app/globals.css +29 -0
- package/template/nextjs/src/app/layout.tsx +45 -18
- package/template/nextjs/src/app/not-found.tsx +25 -3
- package/template/nextjs/src/app/robots.ts +29 -0
- package/template/nextjs/src/app/sitemap.ts +21 -0
- package/template/nextjs/src/components/confirm-dialog.tsx +79 -0
- package/template/nextjs/src/components/dashboard-header.tsx +70 -0
- package/template/nextjs/src/components/data-table/enum.ts +5 -0
- package/template/nextjs/src/components/data-table/features.ts +49 -0
- package/template/nextjs/src/components/data-table/index.tsx +961 -0
- package/template/nextjs/src/components/data-table/types.ts +76 -0
- package/template/nextjs/src/components/error.tsx +71 -0
- package/template/nextjs/src/components/loader.tsx +18 -2
- package/template/nextjs/src/components/logo.tsx +49 -0
- package/template/nextjs/src/components/navigation-search.tsx +140 -0
- package/template/nextjs/src/components/navigation-sidebar.tsx +241 -0
- package/template/nextjs/src/components/page-heading.tsx +38 -0
- package/template/nextjs/src/components/react-query-provider.tsx +41 -2
- package/template/nextjs/src/components/route-error.tsx +55 -0
- package/template/nextjs/src/components/screen-size.tsx +36 -0
- package/template/nextjs/src/components/site-footer.tsx +20 -4
- package/template/nextjs/src/components/theme-provider.tsx +48 -0
- package/template/nextjs/src/components/theme-toggle.tsx +58 -5
- package/template/nextjs/src/components/ui/alert-dialog.tsx +199 -0
- package/template/nextjs/src/components/ui/avatar.tsx +112 -0
- package/template/nextjs/src/components/ui/badge.tsx +54 -0
- package/template/nextjs/src/components/ui/button.tsx +3 -1
- package/template/nextjs/src/components/ui/card.tsx +4 -4
- package/template/nextjs/src/components/ui/collapsible.tsx +33 -0
- package/template/nextjs/src/components/ui/command.tsx +192 -0
- package/template/nextjs/src/components/ui/dialog.tsx +164 -0
- package/template/nextjs/src/components/ui/dropdown-menu.tsx +273 -0
- package/template/nextjs/src/components/ui/input-group.tsx +156 -0
- package/template/nextjs/src/components/ui/select.tsx +195 -0
- package/template/nextjs/src/components/ui/sheet.tsx +143 -0
- package/template/nextjs/src/components/ui/sidebar.tsx +702 -0
- package/template/nextjs/src/components/ui/skeleton.tsx +13 -0
- package/template/nextjs/src/components/ui/table.tsx +116 -0
- package/template/nextjs/src/components/ui/textarea.tsx +18 -0
- package/template/nextjs/src/components/ui/tooltip.tsx +57 -0
- package/template/nextjs/src/components/user-menu.tsx +206 -0
- package/template/nextjs/src/db/common.ts +10 -0
- package/template/nextjs/src/db/index.ts +16 -6
- package/template/nextjs/src/db/relations.ts +21 -0
- package/template/nextjs/src/db/schema.ts +85 -46
- package/template/nextjs/src/emails/components/email-layout.tsx +27 -11
- package/template/nextjs/src/emails/magic-link.tsx +15 -13
- package/template/nextjs/src/emails/test.tsx +11 -9
- package/template/nextjs/src/emails/welcome.tsx +12 -9
- package/template/nextjs/src/env.ts +1 -1
- package/template/nextjs/src/hooks/use-mobile.ts +14 -12
- package/template/nextjs/src/instrumentation.ts +20 -2
- package/template/nextjs/src/lib/actions.ts +55 -0
- package/template/nextjs/src/lib/admin-navigation.ts +43 -0
- package/template/nextjs/src/lib/auth-client.ts +20 -9
- package/template/nextjs/src/lib/auth-permissions.ts +61 -0
- package/template/nextjs/src/lib/auth.ts +33 -3
- package/template/nextjs/src/lib/callback-url.ts +28 -0
- package/template/nextjs/src/lib/constants.ts +21 -0
- package/template/nextjs/src/lib/delay.ts +10 -0
- package/template/nextjs/src/lib/email-service.ts +21 -0
- package/template/nextjs/src/lib/errors.ts +74 -0
- package/template/nextjs/src/lib/format-currency.ts +22 -24
- package/template/nextjs/src/lib/format-date.ts +69 -6
- package/template/nextjs/src/lib/nodemailer.ts +27 -3
- package/template/nextjs/src/lib/otel.ts +92 -2
- package/template/nextjs/src/lib/safe-action-client.ts +60 -9
- package/template/nextjs/src/lib/safe-action.ts +152 -16
- package/template/nextjs/src/lib/search.ts +16 -0
- package/template/nextjs/src/lib/seo.ts +7 -0
- package/template/nextjs/src/lib/siteConfig.ts +17 -1
- package/template/nextjs/src/lib/toast-message.ts +87 -1
- package/template/nextjs/src/lib/validations.ts +30 -0
- package/template/nextjs/src/proxy.ts +48 -0
- package/template/nextjs/src/scripts/reset-db.ts +22 -0
- package/template/nextjs/src/scripts/seed.ts +59 -8
- package/template/nextjs/src/scripts/test-mail.ts +28 -20
- package/template/nextjs/tests/admin/users.test.ts +64 -0
- package/template/nextjs/tests/db/fk-indexes.test.ts +62 -0
- package/template/nextjs/tests/db/seed.test.ts +49 -0
- package/template/nextjs/tests/helpers/action.ts +71 -0
- package/template/nextjs/tests/helpers/fixtures.ts +78 -0
- package/template/nextjs/tests/helpers/index.ts +2 -0
- package/template/nextjs/tests/lib/callback-url.test.ts +48 -0
- package/template/nextjs/tests/lib/client-server-boundary.test.ts +57 -0
- package/template/nextjs/tests/lib/errors.test.ts +10 -0
- package/template/nextjs/tests/lib/search.test.ts +23 -0
- package/template/nextjs/tests/setup/pglite-db.ts +63 -0
- package/template/nextjs/tests/setup/preload.ts +95 -0
- package/template/nextjs/tsconfig.json +1 -0
- package/template/saas-starter/.dockerignore +1 -0
- package/template/saas-starter/.env.example +15 -15
- package/template/saas-starter/AGENTS.md +302 -0
- package/template/saas-starter/CLAUDE.md +1 -0
- package/template/saas-starter/README.md +124 -2
- package/template/saas-starter/bunfig.toml +3 -0
- package/template/saas-starter/eslint.config.mjs +6 -5
- package/template/saas-starter/gitignore +6 -1
- package/template/saas-starter/next.config.ts +19 -1
- package/template/saas-starter/package.json +50 -44
- package/template/saas-starter/public/logo-dark.svg +4 -0
- package/template/saas-starter/public/logo.svg +4 -0
- package/template/saas-starter/src/app/(admin)/actions/contact-leads.ts +51 -0
- package/template/saas-starter/src/app/(admin)/actions/feedbacks.ts +91 -0
- package/template/saas-starter/src/app/(admin)/actions/users.ts +145 -59
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-header.tsx +4 -1
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-sidebar.tsx +12 -10
- package/template/saas-starter/src/app/(admin)/admin/contact-leads/page.tsx +123 -0
- package/template/saas-starter/src/app/(admin)/admin/feedbacks/page.tsx +161 -0
- package/template/saas-starter/src/app/(admin)/admin/layout.tsx +24 -28
- package/template/saas-starter/src/app/(admin)/admin/page.tsx +59 -2
- package/template/saas-starter/src/app/(admin)/admin/settings/layout.tsx +24 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/[userId]/page.tsx +43 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/new/page.tsx +16 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/page.tsx +372 -10
- package/template/saas-starter/src/app/(admin)/admin/settings/users/user-form.tsx +138 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/validation.ts +23 -0
- package/template/saas-starter/src/app/(admin)/admin/support-tickets/[ticketId]/page.tsx +17 -0
- package/template/saas-starter/src/app/(admin)/admin/support-tickets/page.tsx +5 -0
- package/template/saas-starter/src/app/(app)/actions/billing.ts +171 -107
- package/template/saas-starter/src/app/(app)/actions/feedbacks.ts +28 -0
- package/template/saas-starter/src/app/(app)/actions/feedbacks.validation.ts +12 -0
- package/template/saas-starter/src/app/(app)/actions/members.ts +149 -123
- package/template/saas-starter/src/app/(app)/actions/organizations.ts +230 -0
- package/template/saas-starter/src/app/(app)/actions/organizations.validation.ts +17 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/dashboard/page.tsx +6 -9
- package/template/saas-starter/src/app/(app)/app/[orgId]/layout.tsx +6 -9
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/billing-email-form.tsx +45 -53
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/danger-zone.tsx +40 -47
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/general-settings-form.tsx +80 -105
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/plans-section.tsx +72 -82
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/billing/page.tsx +51 -52
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/layout.tsx +24 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/_components/invite-member-dialog.tsx +15 -16
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/_components/members-tabs.tsx +77 -44
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/page.tsx +11 -18
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/page.tsx +14 -28
- package/template/saas-starter/src/app/(app)/app/[orgId]/support-tickets/[ticketId]/page.tsx +25 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/support-tickets/page.tsx +25 -0
- package/template/saas-starter/src/app/(app)/app/_components/app-header.tsx +15 -13
- package/template/saas-starter/src/app/(app)/app/_components/app-search.tsx +15 -6
- package/template/saas-starter/src/app/(app)/app/_components/app-sidebar.tsx +6 -3
- package/template/saas-starter/src/app/(app)/app/_components/feedback-dialog.tsx +108 -0
- package/template/saas-starter/src/app/(app)/app/_components/organization-context.tsx +5 -9
- package/template/saas-starter/src/app/(app)/app/_components/organization-switcher.tsx +68 -8
- package/template/saas-starter/src/app/(app)/app/layout.tsx +44 -32
- package/template/saas-starter/src/app/(app)/app/onboarding/_components/create-organization-form.tsx +75 -87
- package/template/saas-starter/src/app/(app)/app/onboarding/page.tsx +10 -12
- package/template/saas-starter/src/app/(app)/app/page.tsx +16 -21
- package/template/saas-starter/src/app/(auth)/(account)/layout.tsx +64 -0
- package/template/saas-starter/src/app/(auth)/(account)/profile/page.tsx +16 -0
- package/template/saas-starter/src/app/(auth)/(account)/profile/profile-form.tsx +247 -0
- package/template/saas-starter/src/app/(auth)/(account)/support/[ticketId]/page.tsx +19 -0
- package/template/saas-starter/src/app/(auth)/(account)/support/page.tsx +9 -0
- package/template/saas-starter/src/app/(auth)/login/email-login-form.tsx +49 -27
- package/template/saas-starter/src/app/(auth)/login/page.tsx +39 -21
- package/template/saas-starter/src/app/(auth)/login/social-login-buttons.tsx +80 -18
- package/template/saas-starter/src/app/(invitation)/accept-invitation/[id]/accept-invitation-form.tsx +16 -10
- package/template/saas-starter/src/app/(invitation)/accept-invitation/[id]/page.tsx +28 -42
- package/template/saas-starter/src/app/(invitation)/actions/invitations.ts +32 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/actions.ts +23 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/contact-form.tsx +118 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/page.tsx +20 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/validation.ts +22 -0
- package/template/saas-starter/src/app/(marketing)/layout.tsx +38 -4
- package/template/saas-starter/src/app/(marketing)/legal.tsx +66 -0
- package/template/saas-starter/src/app/(marketing)/page.tsx +23 -2
- package/template/saas-starter/src/app/(marketing)/privacy/page.tsx +62 -2
- package/template/saas-starter/src/app/(marketing)/terms/page.tsx +40 -2
- package/template/saas-starter/src/app/actions/support-tickets.ts +510 -0
- package/template/saas-starter/src/app/actions/support-tickets.validation.ts +112 -0
- package/template/saas-starter/src/app/actions/uploads.ts +36 -0
- package/template/saas-starter/src/app/actions/uploads.validation.ts +24 -0
- package/template/saas-starter/src/app/error.tsx +37 -0
- package/template/saas-starter/src/app/fonts/geist-mono/GeistMono-Variable.woff2 +0 -0
- package/template/saas-starter/src/app/fonts/geist-sans/Geist-Variable.woff2 +0 -0
- package/template/saas-starter/src/app/fonts/index.ts +60 -0
- package/template/saas-starter/src/app/global-error.tsx +38 -0
- package/template/saas-starter/src/app/globals.css +29 -0
- package/template/saas-starter/src/app/layout.tsx +43 -19
- package/template/saas-starter/src/app/not-found.tsx +25 -3
- package/template/saas-starter/src/app/robots.ts +14 -10
- package/template/saas-starter/src/app/sitemap.ts +2 -1
- package/template/saas-starter/src/components/confirm-dialog.tsx +79 -0
- package/template/saas-starter/src/components/dashboard-header.tsx +7 -1
- package/template/saas-starter/src/components/data-table/features.ts +49 -0
- package/template/saas-starter/src/components/data-table/index.tsx +65 -64
- package/template/saas-starter/src/components/data-table/types.ts +5 -4
- package/template/saas-starter/src/components/error.tsx +45 -0
- package/template/saas-starter/src/components/file-upload.tsx +65 -26
- package/template/saas-starter/src/components/loader.tsx +18 -2
- package/template/saas-starter/src/components/logo.tsx +49 -0
- package/template/saas-starter/src/components/navigation-search.tsx +2 -2
- package/template/saas-starter/src/components/page-heading.tsx +6 -0
- package/template/saas-starter/src/components/react-query-provider.tsx +41 -2
- package/template/saas-starter/src/components/route-error.tsx +55 -0
- package/template/saas-starter/src/components/screen-size.tsx +36 -0
- package/template/saas-starter/src/components/site-footer.tsx +20 -4
- package/template/saas-starter/src/components/support/create-support-ticket-dialog.tsx +122 -0
- package/template/saas-starter/src/components/support/support-ticket-conversation.tsx +236 -0
- package/template/saas-starter/src/components/support/support-ticket-shared.tsx +58 -0
- package/template/saas-starter/src/components/support/support-tickets-table.tsx +281 -0
- package/template/saas-starter/src/components/theme-provider.tsx +48 -0
- package/template/saas-starter/src/components/theme-toggle.tsx +58 -5
- package/template/saas-starter/src/components/ui/alert-dialog.tsx +199 -0
- package/template/saas-starter/src/components/ui/badge.tsx +6 -1
- package/template/saas-starter/src/components/ui/button.tsx +2 -0
- package/template/saas-starter/src/components/ui/command.tsx +1 -1
- package/template/saas-starter/src/components/user-menu.tsx +147 -24
- package/template/saas-starter/src/db/common.ts +33 -1
- package/template/saas-starter/src/db/enums.ts +24 -0
- package/template/saas-starter/src/db/index.ts +14 -5
- package/template/saas-starter/src/db/relations.ts +40 -3
- package/template/saas-starter/src/db/schema.ts +186 -35
- package/template/saas-starter/src/emails/components/email-layout.tsx +27 -11
- package/template/saas-starter/src/emails/invitation.tsx +34 -21
- package/template/saas-starter/src/emails/magic-link.tsx +15 -13
- package/template/saas-starter/src/emails/test.tsx +11 -9
- package/template/saas-starter/src/emails/welcome.tsx +12 -9
- package/template/saas-starter/src/env.ts +1 -1
- package/template/saas-starter/src/hooks/use-mobile.ts +14 -12
- package/template/saas-starter/src/instrumentation.ts +20 -2
- package/template/saas-starter/src/lib/actions.ts +34 -0
- package/template/saas-starter/src/lib/admin-navigation.ts +33 -1
- package/template/saas-starter/src/lib/app-navigation.ts +45 -41
- package/template/saas-starter/src/lib/auth-client.ts +8 -3
- package/template/saas-starter/src/lib/auth-permissions.ts +50 -11
- package/template/saas-starter/src/lib/auth.ts +122 -21
- package/template/saas-starter/src/lib/billing.ts +59 -24
- package/template/saas-starter/src/lib/callback-url.ts +28 -0
- package/template/saas-starter/src/lib/constants.ts +78 -9
- package/template/saas-starter/src/lib/delay.ts +10 -0
- package/template/saas-starter/src/lib/email-service.ts +30 -1
- package/template/saas-starter/src/lib/errors.ts +74 -0
- package/template/saas-starter/src/lib/format-currency.ts +22 -24
- package/template/saas-starter/src/lib/format-date.ts +69 -6
- package/template/saas-starter/src/lib/image-url.ts +54 -0
- package/template/saas-starter/src/lib/nodemailer.ts +27 -3
- package/template/saas-starter/src/lib/organization-access.ts +56 -76
- package/template/saas-starter/src/lib/otel.ts +92 -2
- package/template/saas-starter/src/lib/plan-limits.ts +37 -0
- package/template/saas-starter/src/lib/plans.ts +40 -13
- package/template/saas-starter/src/lib/rbac.ts +44 -0
- package/template/saas-starter/src/lib/safe-action-client.ts +60 -9
- package/template/saas-starter/src/lib/safe-action.ts +137 -17
- package/template/saas-starter/src/lib/search.ts +16 -0
- package/template/saas-starter/src/lib/seo.ts +7 -0
- package/template/saas-starter/src/lib/siteConfig.ts +17 -1
- package/template/saas-starter/src/lib/storage.ts +176 -46
- package/template/saas-starter/src/lib/stripe.ts +4 -1
- package/template/saas-starter/src/lib/toast-message.ts +87 -1
- package/template/saas-starter/src/lib/validations.ts +85 -2
- package/template/saas-starter/src/proxy.ts +48 -0
- package/template/saas-starter/src/scripts/cleanup-temp-uploads.ts +24 -0
- package/template/saas-starter/src/scripts/seed.ts +82 -8
- package/template/saas-starter/src/scripts/setup-db.ts +72 -0
- package/template/saas-starter/src/scripts/setup-stripe-plans.ts +13 -7
- package/template/saas-starter/src/scripts/test-mail.ts +28 -20
- package/template/saas-starter/tests/admin/users.test.ts +64 -0
- package/template/saas-starter/tests/db/fk-indexes.test.ts +62 -0
- package/template/saas-starter/tests/db/seed.test.ts +57 -0
- package/template/saas-starter/tests/helpers/action.ts +71 -0
- package/template/saas-starter/tests/helpers/fixtures.ts +151 -0
- package/template/saas-starter/tests/helpers/index.ts +2 -0
- package/template/saas-starter/tests/lib/callback-url.test.ts +48 -0
- package/template/saas-starter/tests/lib/client-server-boundary.test.ts +57 -0
- package/template/saas-starter/tests/lib/errors.test.ts +10 -0
- package/template/saas-starter/tests/lib/image-url.test.ts +31 -0
- package/template/saas-starter/tests/lib/search.test.ts +23 -0
- package/template/saas-starter/tests/marketing/contact-and-feedback.test.ts +86 -0
- package/template/saas-starter/tests/organizations/organizations.test.ts +175 -0
- package/template/saas-starter/tests/setup/pglite-db.ts +67 -0
- package/template/saas-starter/tests/setup/preload.ts +108 -0
- package/template/saas-starter/tests/support/support-tickets.test.ts +145 -0
- package/template/saas-starter/tsconfig.json +1 -0
- package/cli.js +0 -147
- package/template/nextjs/src/app/(admin)/layout.tsx +0 -20
- package/template/nextjs/src/app/(app)/layout.tsx +0 -20
- package/template/nextjs/terraform/artifact-registry.tf +0 -5
- package/template/nextjs/terraform/backend-service.tf +0 -13
- package/template/nextjs/terraform/cleanup.sh +0 -9
- package/template/nextjs/terraform/cloudbuild.tf +0 -70
- package/template/nextjs/terraform/cloudrun.tf +0 -68
- package/template/nextjs/terraform/database.tf +0 -60
- package/template/nextjs/terraform/forwarding-rule.tf +0 -43
- package/template/nextjs/terraform/gitignore +0 -4
- package/template/nextjs/terraform/ip-address.tf +0 -11
- package/template/nextjs/terraform/network-endpoint-group.tf +0 -11
- package/template/nextjs/terraform/network.tf +0 -21
- package/template/nextjs/terraform/pre.sh +0 -3
- package/template/nextjs/terraform/providers.tf +0 -18
- package/template/nextjs/terraform/secret.txt +0 -11
- package/template/nextjs/terraform/setup.sh +0 -25
- package/template/nextjs/terraform/ssl-certs.tf +0 -32
- package/template/nextjs/terraform/target-https-proxy copy.tf +0 -14
- package/template/nextjs/terraform/target-https-proxy.tf +0 -14
- package/template/nextjs/terraform/terraform.tfvars +0 -4
- package/template/nextjs/terraform/url-map.tf +0 -23
- package/template/nextjs/terraform/variables.tf +0 -21
- package/template/saas-starter/next-env.d.ts +0 -6
- package/template/saas-starter/src/actions/uploads.ts +0 -28
- package/template/saas-starter/src/actions/uploads.validation.ts +0 -14
- package/template/saas-starter/src/app/(admin)/admin/settings/users/_components/create-user-dialog.tsx +0 -183
- package/template/saas-starter/src/app/(admin)/admin/settings/users/_components/edit-name-dialog.tsx +0 -129
- package/template/saas-starter/src/app/(admin)/admin/settings/users/_components/users-table.tsx +0 -415
- package/template/saas-starter/src/app/(app)/actions/organization.ts +0 -92
- package/template/saas-starter/src/app/proxy.ts +0 -28
- package/template/saas-starter/src/components/impersonation-banner.tsx +0 -44
- package/template/saas-starter/src/lib/organization-plan-limits.ts +0 -38
|
@@ -7,17 +7,79 @@ import { organizationSubscriptionsTable } from '~/db/schema'
|
|
|
7
7
|
import { env } from '~/env'
|
|
8
8
|
import { canStartTrial, ensureStripeCustomer } from '~/lib/billing'
|
|
9
9
|
import { TRIAL_DAYS } from '~/lib/constants'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { AppError, AppErrorCode } from '~/lib/errors'
|
|
11
|
+
import { assertCanManageOrganization } from '~/lib/organization-access'
|
|
12
|
+
import { getOrganizationPlan } from '~/lib/plan-limits'
|
|
13
|
+
import { PLANS, hasLiveSubscription } from '~/lib/plans'
|
|
14
|
+
import { authActionClient, withWideEvent } from '~/lib/safe-action'
|
|
13
15
|
import { stripeClient } from '~/lib/stripe'
|
|
14
16
|
import { emailValidation, stringValidation } from '~/lib/validations'
|
|
15
17
|
|
|
16
|
-
const ACTIVE_STATUSES = ['trialing', 'active', 'past_due'] as const
|
|
17
|
-
|
|
18
18
|
const billingReturnUrl = (organizationId: string) =>
|
|
19
19
|
`${env.BETTER_AUTH_URL}/app/${organizationId}/settings/billing`
|
|
20
20
|
|
|
21
|
+
async function getSubscription(organizationId: string) {
|
|
22
|
+
const sub = await db.query.organizationSubscriptionsTable.findFirst({
|
|
23
|
+
where: eq(organizationSubscriptionsTable.organizationId, organizationId)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if (!sub) {
|
|
27
|
+
throw new AppError(
|
|
28
|
+
AppErrorCode.NOT_FOUND,
|
|
29
|
+
'This organization has no billing record.'
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return sub
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Everything the billing page shows: the current plan and subscription, and
|
|
38
|
+
* each plan's public prices. Stripe price IDs stay on the server.
|
|
39
|
+
*/
|
|
40
|
+
export const getBillingOverview = authActionClient
|
|
41
|
+
.inputSchema(stringValidation)
|
|
42
|
+
.action(
|
|
43
|
+
withWideEvent(
|
|
44
|
+
'getBillingOverview',
|
|
45
|
+
async ({ parsedInput: organizationId, ctx }) => {
|
|
46
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
47
|
+
const { plan, sub } = await getOrganizationPlan(organizationId)
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
currentPlan: { id: plan.id, name: plan.name },
|
|
51
|
+
subscription: {
|
|
52
|
+
status: sub.status,
|
|
53
|
+
billingEmail: sub.billingEmail,
|
|
54
|
+
trialEndsAt: sub.trialEndsAt,
|
|
55
|
+
currentPeriodEnd: sub.currentPeriodEnd,
|
|
56
|
+
cancelAtPeriodEnd: sub.cancelAtPeriodEnd,
|
|
57
|
+
canStartTrial: canStartTrial(sub),
|
|
58
|
+
hasLiveSubscription: hasLiveSubscription(sub.status)
|
|
59
|
+
},
|
|
60
|
+
plans: PLANS.map(item => ({
|
|
61
|
+
id: item.id,
|
|
62
|
+
name: item.name,
|
|
63
|
+
maxMembers: item.maxMembers,
|
|
64
|
+
canUseTrial: Boolean(item.canUseTrial),
|
|
65
|
+
prices: item.stripePrice
|
|
66
|
+
? {
|
|
67
|
+
monthly: {
|
|
68
|
+
amount: item.stripePrice.monthly.amount,
|
|
69
|
+
currency: item.stripePrice.monthly.currency
|
|
70
|
+
},
|
|
71
|
+
annual: {
|
|
72
|
+
amount: item.stripePrice.annual.amount,
|
|
73
|
+
currency: item.stripePrice.annual.currency
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
: null
|
|
77
|
+
}))
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
|
|
21
83
|
export const updateBillingEmailAction = authActionClient
|
|
22
84
|
.inputSchema(
|
|
23
85
|
z.object({
|
|
@@ -25,30 +87,28 @@ export const updateBillingEmailAction = authActionClient
|
|
|
25
87
|
billingEmail: emailValidation
|
|
26
88
|
})
|
|
27
89
|
)
|
|
28
|
-
.action(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
await stripeClient.customers.update(sub.stripeCustomerId, {
|
|
41
|
-
email: billingEmail
|
|
42
|
-
})
|
|
43
|
-
}
|
|
90
|
+
.action(
|
|
91
|
+
withWideEvent(
|
|
92
|
+
'updateBillingEmailAction',
|
|
93
|
+
async ({ parsedInput: { organizationId, billingEmail }, ctx }) => {
|
|
94
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
95
|
+
const sub = await getSubscription(organizationId)
|
|
96
|
+
|
|
97
|
+
if (sub.stripeCustomerId) {
|
|
98
|
+
await stripeClient.customers.update(sub.stripeCustomerId, {
|
|
99
|
+
email: billingEmail
|
|
100
|
+
})
|
|
101
|
+
}
|
|
44
102
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
103
|
+
await db
|
|
104
|
+
.update(organizationSubscriptionsTable)
|
|
105
|
+
.set({ billingEmail })
|
|
106
|
+
.where(eq(organizationSubscriptionsTable.id, sub.id))
|
|
49
107
|
|
|
50
|
-
|
|
51
|
-
|
|
108
|
+
return true
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
)
|
|
52
112
|
|
|
53
113
|
export const createCheckoutSessionAction = authActionClient
|
|
54
114
|
.inputSchema(
|
|
@@ -60,93 +120,97 @@ export const createCheckoutSessionAction = authActionClient
|
|
|
60
120
|
})
|
|
61
121
|
)
|
|
62
122
|
.action(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'This organization already has a subscription. Manage it from the billing portal.'
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const planDef = PLANS.find(p => p.id === plan)
|
|
81
|
-
const price = planDef?.stripePrice?.[interval]
|
|
82
|
-
if (!price) {
|
|
83
|
-
throw new Error('Selected plan is not available')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const trialAllowed =
|
|
87
|
-
withTrial && Boolean(planDef?.canUseTrial) && canStartTrial(sub)
|
|
88
|
-
|
|
89
|
-
const customerId = await ensureStripeCustomer(organizationId)
|
|
90
|
-
|
|
91
|
-
if (trialAllowed) {
|
|
92
|
-
await db
|
|
93
|
-
.update(organizationSubscriptionsTable)
|
|
94
|
-
.set({ hasUsedTrial: true })
|
|
95
|
-
.where(
|
|
96
|
-
eq(organizationSubscriptionsTable.organizationId, organizationId)
|
|
123
|
+
withWideEvent(
|
|
124
|
+
'createCheckoutSessionAction',
|
|
125
|
+
async ({
|
|
126
|
+
parsedInput: { organizationId, plan, interval, withTrial },
|
|
127
|
+
ctx
|
|
128
|
+
}) => {
|
|
129
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
130
|
+
const sub = await getSubscription(organizationId)
|
|
131
|
+
|
|
132
|
+
if (hasLiveSubscription(sub.status) || sub.stripeSubscriptionId) {
|
|
133
|
+
throw new AppError(
|
|
134
|
+
AppErrorCode.CONFLICT,
|
|
135
|
+
'This organization already has a subscription. Change plans from Manage Billing.'
|
|
97
136
|
)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const planDef = PLANS.find(item => item.id === plan)
|
|
140
|
+
const price = planDef?.stripePrice?.[interval]
|
|
141
|
+
if (!price) {
|
|
142
|
+
throw new AppError(
|
|
143
|
+
AppErrorCode.BAD_REQUEST,
|
|
144
|
+
'That plan is not available. Choose another plan.'
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// The webhook marks the trial as used once Stripe starts it, so an
|
|
149
|
+
// abandoned checkout does not use it up.
|
|
150
|
+
const trialAllowed =
|
|
151
|
+
withTrial && Boolean(planDef?.canUseTrial) && canStartTrial(sub)
|
|
152
|
+
|
|
153
|
+
const customerId = await ensureStripeCustomer(sub)
|
|
154
|
+
|
|
155
|
+
const session = await stripeClient.checkout.sessions.create({
|
|
156
|
+
mode: 'subscription',
|
|
157
|
+
customer: customerId,
|
|
158
|
+
line_items: [{ price: price.id, quantity: 1 }],
|
|
159
|
+
client_reference_id: organizationId,
|
|
160
|
+
allow_promotion_codes: true,
|
|
161
|
+
success_url: `${billingReturnUrl(organizationId)}?checkout=success`,
|
|
162
|
+
cancel_url: `${billingReturnUrl(organizationId)}?checkout=cancel`,
|
|
163
|
+
subscription_data: {
|
|
164
|
+
metadata: { organizationId },
|
|
165
|
+
...(trialAllowed
|
|
166
|
+
? {
|
|
167
|
+
trial_period_days: TRIAL_DAYS,
|
|
168
|
+
trial_settings: {
|
|
169
|
+
end_behavior: { missing_payment_method: 'cancel' }
|
|
170
|
+
}
|
|
115
171
|
}
|
|
116
|
-
}
|
|
172
|
+
: {})
|
|
173
|
+
},
|
|
174
|
+
...(trialAllowed
|
|
175
|
+
? { payment_method_collection: 'always' as const }
|
|
117
176
|
: {})
|
|
118
|
-
}
|
|
119
|
-
...(trialAllowed
|
|
120
|
-
? { payment_method_collection: 'always' as const }
|
|
121
|
-
: {})
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
if (!session.url) {
|
|
125
|
-
throw new Error('Failed to create checkout session')
|
|
126
|
-
}
|
|
177
|
+
})
|
|
127
178
|
|
|
128
|
-
|
|
129
|
-
|
|
179
|
+
if (!session.url) {
|
|
180
|
+
throw new AppError(
|
|
181
|
+
AppErrorCode.INTERNAL,
|
|
182
|
+
'Stripe did not return a checkout page. Try again.'
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return { url: session.url }
|
|
187
|
+
}
|
|
188
|
+
)
|
|
130
189
|
)
|
|
131
190
|
|
|
132
191
|
export const createPortalSessionAction = authActionClient
|
|
133
192
|
.inputSchema(z.object({ organizationId: stringValidation }))
|
|
134
|
-
.action(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
193
|
+
.action(
|
|
194
|
+
withWideEvent(
|
|
195
|
+
'createPortalSessionAction',
|
|
196
|
+
async ({ parsedInput: { organizationId }, ctx }) => {
|
|
197
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
198
|
+
const sub = await getSubscription(organizationId)
|
|
199
|
+
|
|
200
|
+
if (!sub.stripeCustomerId) {
|
|
201
|
+
throw new AppError(
|
|
202
|
+
AppErrorCode.BAD_REQUEST,
|
|
203
|
+
'This organization has no billing account yet. Choose a paid plan first.'
|
|
204
|
+
)
|
|
205
|
+
}
|
|
144
206
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
207
|
+
const session = await stripeClient.billingPortal.sessions.create({
|
|
208
|
+
customer: sub.stripeCustomerId,
|
|
209
|
+
return_url: billingReturnUrl(organizationId),
|
|
210
|
+
configuration: env.STRIPE_PORTAL_CONFIGURATION_ID
|
|
211
|
+
})
|
|
150
212
|
|
|
151
|
-
|
|
152
|
-
|
|
213
|
+
return { url: session.url }
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use server'
|
|
2
|
+
|
|
3
|
+
import { db } from '~/db'
|
|
4
|
+
import { feedbacksTable } from '~/db/schema'
|
|
5
|
+
import { assertMember } from '~/lib/organization-access'
|
|
6
|
+
import { authActionClient, withWideEvent } from '~/lib/safe-action'
|
|
7
|
+
import { createFeedbackSchema } from './feedbacks.validation'
|
|
8
|
+
|
|
9
|
+
/** Any member can rate the product from inside an organization. */
|
|
10
|
+
export const createFeedbackAction = authActionClient
|
|
11
|
+
.inputSchema(createFeedbackSchema)
|
|
12
|
+
.action(
|
|
13
|
+
withWideEvent('createFeedbackAction', async ({ parsedInput, ctx }) => {
|
|
14
|
+
await assertMember(parsedInput.organizationId, ctx.user.id)
|
|
15
|
+
|
|
16
|
+
const [feedback] = await db
|
|
17
|
+
.insert(feedbacksTable)
|
|
18
|
+
.values({
|
|
19
|
+
userId: ctx.user.id,
|
|
20
|
+
organizationId: parsedInput.organizationId,
|
|
21
|
+
rating: parsedInput.rating,
|
|
22
|
+
comment: parsedInput.comment
|
|
23
|
+
})
|
|
24
|
+
.returning()
|
|
25
|
+
|
|
26
|
+
return feedback
|
|
27
|
+
})
|
|
28
|
+
)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import {
|
|
3
|
+
ratingValidation,
|
|
4
|
+
requiredCommentValidation,
|
|
5
|
+
stringValidation
|
|
6
|
+
} from '~/lib/validations'
|
|
7
|
+
|
|
8
|
+
export const createFeedbackSchema = z.object({
|
|
9
|
+
organizationId: stringValidation,
|
|
10
|
+
rating: ratingValidation,
|
|
11
|
+
comment: requiredCommentValidation
|
|
12
|
+
})
|
|
@@ -6,10 +6,12 @@ import { SortOrderEnum } from '~/components/data-table/enum'
|
|
|
6
6
|
import { db } from '~/db'
|
|
7
7
|
import { invitationsTable, membersTable, usersTable } from '~/db/schema'
|
|
8
8
|
import { getPaginationSchema, getSortSchema } from '~/lib/actions'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
import { MAX_FILTER_VALUES } from '~/lib/constants'
|
|
10
|
+
import { assertCanManageOrganization } from '~/lib/organization-access'
|
|
11
|
+
import { getOrganizationPlan } from '~/lib/plan-limits'
|
|
12
|
+
import { authActionClient, withWideEvent } from '~/lib/safe-action'
|
|
13
|
+
import { likeContains } from '~/lib/search'
|
|
14
|
+
import { optionalStringValidation, stringValidation } from '~/lib/validations'
|
|
13
15
|
|
|
14
16
|
export const getMembers = authActionClient
|
|
15
17
|
.inputSchema(
|
|
@@ -17,83 +19,82 @@ export const getMembers = authActionClient
|
|
|
17
19
|
organizationId: stringValidation,
|
|
18
20
|
...getPaginationSchema(),
|
|
19
21
|
...getSortSchema(['name', 'email', 'role', 'createdAt']),
|
|
20
|
-
search:
|
|
22
|
+
search: optionalStringValidation,
|
|
21
23
|
filters: z
|
|
22
24
|
.object({
|
|
23
|
-
role: z.array(z.string()).optional()
|
|
25
|
+
role: z.array(z.string()).max(MAX_FILTER_VALUES).optional()
|
|
24
26
|
})
|
|
25
27
|
.optional()
|
|
26
28
|
})
|
|
27
29
|
)
|
|
28
30
|
.action(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
withWideEvent(
|
|
32
|
+
'getMembers',
|
|
33
|
+
async ({
|
|
34
|
+
parsedInput: {
|
|
35
|
+
organizationId,
|
|
36
|
+
page,
|
|
37
|
+
limit,
|
|
38
|
+
sortBy,
|
|
39
|
+
sortOrder,
|
|
40
|
+
search,
|
|
41
|
+
filters
|
|
42
|
+
},
|
|
43
|
+
ctx
|
|
44
|
+
}) => {
|
|
45
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
46
|
+
|
|
47
|
+
const where = and(
|
|
48
|
+
eq(membersTable.organizationId, organizationId),
|
|
49
|
+
search
|
|
50
|
+
? or(
|
|
51
|
+
ilike(usersTable.name, likeContains(search)),
|
|
52
|
+
ilike(usersTable.email, likeContains(search))
|
|
53
|
+
)
|
|
54
|
+
: undefined,
|
|
55
|
+
filters?.role?.length
|
|
56
|
+
? inArray(membersTable.role, filters.role)
|
|
57
|
+
: undefined
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const sortColumn =
|
|
61
|
+
sortBy === 'name'
|
|
62
|
+
? usersTable.name
|
|
63
|
+
: sortBy === 'email'
|
|
64
|
+
? usersTable.email
|
|
65
|
+
: sortBy === 'role'
|
|
66
|
+
? membersTable.role
|
|
67
|
+
: membersTable.createdAt
|
|
68
|
+
|
|
69
|
+
const direction = sortOrder === SortOrderEnum.ASC ? asc : desc
|
|
70
|
+
|
|
71
|
+
const [rows, total] = await Promise.all([
|
|
72
|
+
db
|
|
73
|
+
.select({
|
|
74
|
+
id: membersTable.id,
|
|
75
|
+
userId: usersTable.id,
|
|
76
|
+
name: usersTable.name,
|
|
77
|
+
email: usersTable.email,
|
|
78
|
+
image: usersTable.image,
|
|
79
|
+
role: membersTable.role,
|
|
80
|
+
createdAt: membersTable.createdAt
|
|
81
|
+
})
|
|
82
|
+
.from(membersTable)
|
|
83
|
+
.innerJoin(usersTable, eq(membersTable.userId, usersTable.id))
|
|
84
|
+
.where(where)
|
|
85
|
+
.orderBy(direction(sortColumn))
|
|
86
|
+
.limit(limit)
|
|
87
|
+
.offset((page - 1) * limit),
|
|
88
|
+
db
|
|
89
|
+
.select({ count: count() })
|
|
90
|
+
.from(membersTable)
|
|
91
|
+
.innerJoin(usersTable, eq(membersTable.userId, usersTable.id))
|
|
92
|
+
.where(where)
|
|
93
|
+
])
|
|
94
|
+
|
|
95
|
+
return [rows, total[0]?.count ?? 0] as const
|
|
38
96
|
}
|
|
39
|
-
|
|
40
|
-
await assertUserCanManageOrganization(organizationId)
|
|
41
|
-
|
|
42
|
-
const where = and(
|
|
43
|
-
eq(membersTable.organizationId, organizationId),
|
|
44
|
-
search
|
|
45
|
-
? or(
|
|
46
|
-
ilike(usersTable.name, `%${search}%`),
|
|
47
|
-
ilike(usersTable.email, `%${search}%`)
|
|
48
|
-
)
|
|
49
|
-
: undefined,
|
|
50
|
-
filters?.role && filters.role.length > 0
|
|
51
|
-
? inArray(membersTable.role, filters.role)
|
|
52
|
-
: undefined
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const sortColumn =
|
|
56
|
-
sortBy === 'name'
|
|
57
|
-
? usersTable.name
|
|
58
|
-
: sortBy === 'email'
|
|
59
|
-
? usersTable.email
|
|
60
|
-
: sortBy === 'role'
|
|
61
|
-
? membersTable.role
|
|
62
|
-
: membersTable.createdAt
|
|
63
|
-
|
|
64
|
-
const direction = sortOrder === SortOrderEnum.ASC ? asc : desc
|
|
65
|
-
|
|
66
|
-
const [rows, total] = await Promise.all([
|
|
67
|
-
db
|
|
68
|
-
.select({
|
|
69
|
-
id: membersTable.id,
|
|
70
|
-
userId: usersTable.id,
|
|
71
|
-
name: usersTable.name,
|
|
72
|
-
email: usersTable.email,
|
|
73
|
-
image: usersTable.image,
|
|
74
|
-
role: membersTable.role,
|
|
75
|
-
createdAt: membersTable.createdAt
|
|
76
|
-
})
|
|
77
|
-
.from(membersTable)
|
|
78
|
-
.innerJoin(usersTable, eq(membersTable.userId, usersTable.id))
|
|
79
|
-
.where(where)
|
|
80
|
-
.orderBy(direction(sortColumn))
|
|
81
|
-
.limit(limit)
|
|
82
|
-
.offset((page - 1) * limit),
|
|
83
|
-
db
|
|
84
|
-
.select({ count: count() })
|
|
85
|
-
.from(membersTable)
|
|
86
|
-
.innerJoin(usersTable, eq(membersTable.userId, usersTable.id))
|
|
87
|
-
.where(where)
|
|
88
|
-
])
|
|
89
|
-
|
|
90
|
-
const data = rows.map(row => ({
|
|
91
|
-
...row,
|
|
92
|
-
image: resolveImageUrl(row.image)
|
|
93
|
-
}))
|
|
94
|
-
|
|
95
|
-
return [data, total[0]?.count ?? 0] as const
|
|
96
|
-
}
|
|
97
|
+
)
|
|
97
98
|
)
|
|
98
99
|
|
|
99
100
|
export const getInvitations = authActionClient
|
|
@@ -102,62 +103,87 @@ export const getInvitations = authActionClient
|
|
|
102
103
|
organizationId: stringValidation,
|
|
103
104
|
...getPaginationSchema(),
|
|
104
105
|
...getSortSchema(['email', 'status', 'createdAt', 'expiresAt']),
|
|
105
|
-
search:
|
|
106
|
+
search: optionalStringValidation,
|
|
106
107
|
filters: z
|
|
107
108
|
.object({
|
|
108
|
-
status: z.array(z.string()).optional()
|
|
109
|
+
status: z.array(z.string()).max(MAX_FILTER_VALUES).optional()
|
|
109
110
|
})
|
|
110
111
|
.optional()
|
|
111
112
|
})
|
|
112
113
|
)
|
|
113
114
|
.action(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
sortOrder,
|
|
121
|
-
search,
|
|
122
|
-
filters
|
|
123
|
-
}
|
|
124
|
-
}) => {
|
|
125
|
-
await assertUserCanManageOrganization(organizationId)
|
|
126
|
-
|
|
127
|
-
const where = and(
|
|
128
|
-
eq(invitationsTable.organizationId, organizationId),
|
|
129
|
-
search ? ilike(invitationsTable.email, `%${search}%`) : undefined,
|
|
130
|
-
filters?.status && filters.status.length > 0
|
|
131
|
-
? inArray(invitationsTable.status, filters.status)
|
|
132
|
-
: undefined
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
const sortColumn = invitationsTable[sortBy ?? 'createdAt']
|
|
136
|
-
const direction = sortOrder === SortOrderEnum.ASC ? asc : desc
|
|
137
|
-
|
|
138
|
-
const [rows, total] = await Promise.all([
|
|
139
|
-
db.query.invitationsTable.findMany({
|
|
140
|
-
where,
|
|
141
|
-
with: {
|
|
142
|
-
user: { columns: { name: true } }
|
|
143
|
-
},
|
|
115
|
+
withWideEvent(
|
|
116
|
+
'getInvitations',
|
|
117
|
+
async ({
|
|
118
|
+
parsedInput: {
|
|
119
|
+
organizationId,
|
|
120
|
+
page,
|
|
144
121
|
limit,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
122
|
+
sortBy,
|
|
123
|
+
sortOrder,
|
|
124
|
+
search,
|
|
125
|
+
filters
|
|
126
|
+
},
|
|
127
|
+
ctx
|
|
128
|
+
}) => {
|
|
129
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
130
|
+
|
|
131
|
+
const where = and(
|
|
132
|
+
eq(invitationsTable.organizationId, organizationId),
|
|
133
|
+
search
|
|
134
|
+
? ilike(invitationsTable.email, likeContains(search))
|
|
135
|
+
: undefined,
|
|
136
|
+
filters?.status?.length
|
|
137
|
+
? inArray(invitationsTable.status, filters.status)
|
|
138
|
+
: undefined
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
const direction = sortOrder === SortOrderEnum.ASC ? asc : desc
|
|
142
|
+
|
|
143
|
+
const [rows, total] = await Promise.all([
|
|
144
|
+
db.query.invitationsTable.findMany({
|
|
145
|
+
where,
|
|
146
|
+
with: { inviter: { columns: { name: true } } },
|
|
147
|
+
limit,
|
|
148
|
+
offset: (page - 1) * limit,
|
|
149
|
+
orderBy: [direction(invitationsTable[sortBy ?? 'createdAt'])]
|
|
150
|
+
}),
|
|
151
|
+
db.select({ count: count() }).from(invitationsTable).where(where)
|
|
152
|
+
])
|
|
153
|
+
|
|
154
|
+
const data = rows.map(row => ({
|
|
155
|
+
id: row.id,
|
|
156
|
+
email: row.email,
|
|
157
|
+
role: row.role ?? 'member',
|
|
158
|
+
status: row.status,
|
|
159
|
+
expiresAt: row.expiresAt,
|
|
160
|
+
createdAt: row.createdAt,
|
|
161
|
+
inviterName: row.inviter?.name ?? null
|
|
162
|
+
}))
|
|
163
|
+
|
|
164
|
+
return [data, total[0]?.count ?? 0] as const
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
/** Member count and the plan's member limit, for the invite button. */
|
|
170
|
+
export const getMemberUsage = authActionClient
|
|
171
|
+
.inputSchema(stringValidation)
|
|
172
|
+
.action(
|
|
173
|
+
withWideEvent(
|
|
174
|
+
'getMemberUsage',
|
|
175
|
+
async ({ parsedInput: organizationId, ctx }) => {
|
|
176
|
+
await assertCanManageOrganization(organizationId, ctx.user.id)
|
|
177
|
+
|
|
178
|
+
const [[row], { plan }] = await Promise.all([
|
|
179
|
+
db
|
|
180
|
+
.select({ count: count() })
|
|
181
|
+
.from(membersTable)
|
|
182
|
+
.where(eq(membersTable.organizationId, organizationId)),
|
|
183
|
+
getOrganizationPlan(organizationId)
|
|
184
|
+
])
|
|
185
|
+
|
|
186
|
+
return { memberCount: row?.count ?? 0, maxMembers: plan.maxMembers }
|
|
187
|
+
}
|
|
188
|
+
)
|
|
163
189
|
)
|