create-pet-adopt 0.0.0 → 0.3.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/LICENSE +21 -0
- package/README.md +120 -0
- package/index.js +920 -0
- package/package.json +43 -1
- package/template/.env.example +136 -0
- package/template/.pet-adopt/template.json +581 -0
- package/template/LICENSE +21 -0
- package/template/README.md +109 -0
- package/template/_gitignore +28 -0
- package/template/_pnpm-lock.yaml +9251 -0
- package/template/assets/sample-pet.png +0 -0
- package/template/components.json +25 -0
- package/template/docker-compose.yml +110 -0
- package/template/drizzle/pg/0000_initial.sql +176 -0
- package/template/drizzle/pg/0001_greedy_the_renegades.sql +1 -0
- package/template/drizzle/pg/0002_fuzzy_the_renegades.sql +1 -0
- package/template/drizzle/pg/0003_thin_multiple_man.sql +1 -0
- package/template/drizzle/pg/0004_boring_norman_osborn.sql +15 -0
- package/template/drizzle/pg/0005_bitter_proemial_gods.sql +3 -0
- package/template/drizzle/pg/0006_friendly_black_knight.sql +2 -0
- package/template/drizzle/pg/0007_wise_ozymandias.sql +11 -0
- package/template/drizzle/pg/0008_messy_human_fly.sql +2 -0
- package/template/drizzle/pg/0009_amused_lady_bullseye.sql +1 -0
- package/template/drizzle/pg/0010_cute_mauler.sql +7 -0
- package/template/drizzle/pg/0011_clear_purple_man.sql +3 -0
- package/template/drizzle/pg/0012_tiresome_gunslinger.sql +2 -0
- package/template/drizzle/pg/0013_awesome_wong.sql +18 -0
- package/template/drizzle/pg/0014_fantastic_sumo.sql +12 -0
- package/template/drizzle/pg/0015_pink_carnage.sql +12 -0
- package/template/drizzle/pg/0016_sloppy_king_bedlam.sql +2 -0
- package/template/drizzle/pg/0017_steep_warhawk.sql +15 -0
- package/template/drizzle/pg/0018_mixed_otto_octavius.sql +4 -0
- package/template/drizzle/pg/0019_talented_rocket_raccoon.sql +1 -0
- package/template/drizzle/pg/0020_worthless_zodiak.sql +19 -0
- package/template/drizzle/pg/0021_adorable_squadron_supreme.sql +1 -0
- package/template/drizzle/pg/0022_soft_pixie.sql +5 -0
- package/template/drizzle/pg/0023_fluffy_quasar.sql +1 -0
- package/template/drizzle/pg/0024_uneven_ken_ellis.sql +2 -0
- package/template/drizzle/pg/0025_rich_white_queen.sql +3 -0
- package/template/drizzle/pg/0026_spooky_komodo.sql +16 -0
- package/template/drizzle/pg/0027_big_thunderbolts.sql +2 -0
- package/template/drizzle/pg/meta/0000_snapshot.json +1265 -0
- package/template/drizzle/pg/meta/0001_snapshot.json +1272 -0
- package/template/drizzle/pg/meta/0002_snapshot.json +1278 -0
- package/template/drizzle/pg/meta/0003_snapshot.json +1284 -0
- package/template/drizzle/pg/meta/0004_snapshot.json +1401 -0
- package/template/drizzle/pg/meta/0005_snapshot.json +1401 -0
- package/template/drizzle/pg/meta/0006_snapshot.json +1414 -0
- package/template/drizzle/pg/meta/0007_snapshot.json +1485 -0
- package/template/drizzle/pg/meta/0008_snapshot.json +1504 -0
- package/template/drizzle/pg/meta/0009_snapshot.json +1510 -0
- package/template/drizzle/pg/meta/0010_snapshot.json +1556 -0
- package/template/drizzle/pg/meta/0011_snapshot.json +1574 -0
- package/template/drizzle/pg/meta/0012_snapshot.json +1586 -0
- package/template/drizzle/pg/meta/0013_snapshot.json +1730 -0
- package/template/drizzle/pg/meta/0014_snapshot.json +1805 -0
- package/template/drizzle/pg/meta/0015_snapshot.json +1883 -0
- package/template/drizzle/pg/meta/0016_snapshot.json +1897 -0
- package/template/drizzle/pg/meta/0017_snapshot.json +2013 -0
- package/template/drizzle/pg/meta/0018_snapshot.json +1988 -0
- package/template/drizzle/pg/meta/0019_snapshot.json +1994 -0
- package/template/drizzle/pg/meta/0020_snapshot.json +2108 -0
- package/template/drizzle/pg/meta/0021_snapshot.json +2114 -0
- package/template/drizzle/pg/meta/0022_snapshot.json +2126 -0
- package/template/drizzle/pg/meta/0023_snapshot.json +2132 -0
- package/template/drizzle/pg/meta/0024_snapshot.json +2151 -0
- package/template/drizzle/pg/meta/0025_snapshot.json +2169 -0
- package/template/drizzle/pg/meta/0026_snapshot.json +2294 -0
- package/template/drizzle/pg/meta/0027_snapshot.json +2330 -0
- package/template/drizzle/pg/meta/_journal.json +202 -0
- package/template/drizzle/sqlite/0000_initial.sql +176 -0
- package/template/drizzle/sqlite/0001_easy_sebastian_shaw.sql +1 -0
- package/template/drizzle/sqlite/0002_past_king_cobra.sql +1 -0
- package/template/drizzle/sqlite/0003_organic_masked_marvel.sql +1 -0
- package/template/drizzle/sqlite/0004_panoramic_inhumans.sql +15 -0
- package/template/drizzle/sqlite/0005_small_sunset_bain.sql +19 -0
- package/template/drizzle/sqlite/0006_narrow_medusa.sql +2 -0
- package/template/drizzle/sqlite/0007_gray_grandmaster.sql +10 -0
- package/template/drizzle/sqlite/0008_chief_toxin.sql +1 -0
- package/template/drizzle/sqlite/0009_vengeful_tag.sql +1 -0
- package/template/drizzle/sqlite/0010_kind_klaw.sql +7 -0
- package/template/drizzle/sqlite/0011_overrated_meltdown.sql +3 -0
- package/template/drizzle/sqlite/0012_robust_next_avengers.sql +2 -0
- package/template/drizzle/sqlite/0013_melodic_kitty_pryde.sql +18 -0
- package/template/drizzle/sqlite/0014_stormy_cyclops.sql +12 -0
- package/template/drizzle/sqlite/0015_parallel_mongu.sql +11 -0
- package/template/drizzle/sqlite/0016_grey_quicksilver.sql +2 -0
- package/template/drizzle/sqlite/0017_daily_psylocke.sql +15 -0
- package/template/drizzle/sqlite/0018_whole_redwing.sql +4 -0
- package/template/drizzle/sqlite/0019_spotty_mandroid.sql +1 -0
- package/template/drizzle/sqlite/0020_wild_wendell_rand.sql +19 -0
- package/template/drizzle/sqlite/0021_calm_lockheed.sql +1 -0
- package/template/drizzle/sqlite/0022_lonely_emma_frost.sql +5 -0
- package/template/drizzle/sqlite/0023_elite_tony_stark.sql +1 -0
- package/template/drizzle/sqlite/0024_little_lily_hollister.sql +1 -0
- package/template/drizzle/sqlite/0025_tough_shotgun.sql +3 -0
- package/template/drizzle/sqlite/0026_faithful_mephistopheles.sql +16 -0
- package/template/drizzle/sqlite/0027_rapid_arclight.sql +2 -0
- package/template/drizzle/sqlite/meta/0000_snapshot.json +1237 -0
- package/template/drizzle/sqlite/meta/0001_snapshot.json +1245 -0
- package/template/drizzle/sqlite/meta/0002_snapshot.json +1252 -0
- package/template/drizzle/sqlite/meta/0003_snapshot.json +1259 -0
- package/template/drizzle/sqlite/meta/0004_snapshot.json +1369 -0
- package/template/drizzle/sqlite/meta/0005_snapshot.json +1369 -0
- package/template/drizzle/sqlite/meta/0006_snapshot.json +1384 -0
- package/template/drizzle/sqlite/meta/0007_snapshot.json +1459 -0
- package/template/drizzle/sqlite/meta/0008_snapshot.json +1479 -0
- package/template/drizzle/sqlite/meta/0009_snapshot.json +1486 -0
- package/template/drizzle/sqlite/meta/0010_snapshot.json +1533 -0
- package/template/drizzle/sqlite/meta/0011_snapshot.json +1554 -0
- package/template/drizzle/sqlite/meta/0012_snapshot.json +1568 -0
- package/template/drizzle/sqlite/meta/0013_snapshot.json +1687 -0
- package/template/drizzle/sqlite/meta/0014_snapshot.json +1769 -0
- package/template/drizzle/sqlite/meta/0015_snapshot.json +1852 -0
- package/template/drizzle/sqlite/meta/0016_snapshot.json +1867 -0
- package/template/drizzle/sqlite/meta/0017_snapshot.json +1973 -0
- package/template/drizzle/sqlite/meta/0018_snapshot.json +1944 -0
- package/template/drizzle/sqlite/meta/0019_snapshot.json +1951 -0
- package/template/drizzle/sqlite/meta/0020_snapshot.json +2077 -0
- package/template/drizzle/sqlite/meta/0021_snapshot.json +2084 -0
- package/template/drizzle/sqlite/meta/0022_snapshot.json +2098 -0
- package/template/drizzle/sqlite/meta/0023_snapshot.json +2105 -0
- package/template/drizzle/sqlite/meta/0024_snapshot.json +2125 -0
- package/template/drizzle/sqlite/meta/0025_snapshot.json +2146 -0
- package/template/drizzle/sqlite/meta/0026_snapshot.json +2265 -0
- package/template/drizzle/sqlite/meta/0027_snapshot.json +2280 -0
- package/template/drizzle/sqlite/meta/_journal.json +202 -0
- package/template/drizzle.pg.config.ts +8 -0
- package/template/drizzle.sqlite.config.ts +8 -0
- package/template/eslint.config.mjs +22 -0
- package/template/next.config.ts +153 -0
- package/template/package.json +102 -0
- package/template/pet-adopt.blocks.ts +9 -0
- package/template/pet-adopt.config.ts +17 -0
- package/template/pnpm-workspace.yaml +19 -0
- package/template/postcss.config.mjs +5 -0
- package/template/scripts/check-routes.ts +405 -0
- package/template/scripts/check-schemas.ts +58 -0
- package/template/scripts/migrate-all.ts +25 -0
- package/template/scripts/migrate-on-build.ts +71 -0
- package/template/scripts/migrate.ts +20 -0
- package/template/scripts/plugin-generate.ts +92 -0
- package/template/scripts/reset-password.ts +45 -0
- package/template/scripts/reset-two-factor.ts +53 -0
- package/template/scripts/seed.ts +79 -0
- package/template/scripts/setup-env.ts +91 -0
- package/template/scripts/storage-check.ts +53 -0
- package/template/src/app/(admin)/admin/account/AccountForms.tsx +194 -0
- package/template/src/app/(admin)/admin/account/page.tsx +59 -0
- package/template/src/app/(admin)/admin/activity/page.tsx +76 -0
- package/template/src/app/(admin)/admin/authentication/archived/page.tsx +24 -0
- package/template/src/app/(admin)/admin/authentication/layout.tsx +20 -0
- package/template/src/app/(admin)/admin/authentication/page.tsx +36 -0
- package/template/src/app/(admin)/admin/authentication/providers/page.tsx +33 -0
- package/template/src/app/(admin)/admin/email/layout.tsx +21 -0
- package/template/src/app/(admin)/admin/email/page.tsx +43 -0
- package/template/src/app/(admin)/admin/email/templates/page.tsx +38 -0
- package/template/src/app/(admin)/admin/error.tsx +36 -0
- package/template/src/app/(admin)/admin/layout.tsx +26 -0
- package/template/src/app/(admin)/admin/loading.tsx +9 -0
- package/template/src/app/(admin)/admin/media/[id]/page.tsx +97 -0
- package/template/src/app/(admin)/admin/media/page.tsx +34 -0
- package/template/src/app/(admin)/admin/media/search-params.ts +16 -0
- package/template/src/app/(admin)/admin/page.tsx +79 -0
- package/template/src/app/(admin)/admin/pages/PageForm.tsx +604 -0
- package/template/src/app/(admin)/admin/pages/[id]/page.tsx +51 -0
- package/template/src/app/(admin)/admin/pages/new/page.tsx +19 -0
- package/template/src/app/(admin)/admin/pages/page.tsx +49 -0
- package/template/src/app/(admin)/admin/pets/PetForm.tsx +437 -0
- package/template/src/app/(admin)/admin/pets/[id]/page.tsx +41 -0
- package/template/src/app/(admin)/admin/pets/new/page.tsx +26 -0
- package/template/src/app/(admin)/admin/pets/page.tsx +70 -0
- package/template/src/app/(admin)/admin/pets/search-params.ts +16 -0
- package/template/src/app/(admin)/admin/plugins/[plugin]/[[...path]]/page.tsx +73 -0
- package/template/src/app/(admin)/admin/plugins/page.tsx +66 -0
- package/template/src/app/(admin)/admin/settings/SettingsForm.tsx +644 -0
- package/template/src/app/(admin)/admin/settings/email/page.tsx +9 -0
- package/template/src/app/(admin)/admin/settings/page.tsx +40 -0
- package/template/src/app/(admin)/admin/settings/templates/page.tsx +9 -0
- package/template/src/app/(admin)/admin/theme/[id]/page.tsx +28 -0
- package/template/src/app/(admin)/admin/theme/page.tsx +30 -0
- package/template/src/app/(admin)/admin/users/page.tsx +33 -0
- package/template/src/app/(admin)/layout.tsx +75 -0
- package/template/src/app/(admin)/providers.tsx +42 -0
- package/template/src/app/(auth)/admin/confirm-email/page.tsx +40 -0
- package/template/src/app/(auth)/admin/invite/page.tsx +38 -0
- package/template/src/app/(auth)/admin/login/DemoSignIn.tsx +69 -0
- package/template/src/app/(auth)/admin/login/page.tsx +83 -0
- package/template/src/app/(auth)/admin/reset-password/page.tsx +73 -0
- package/template/src/app/(auth)/error.tsx +9 -0
- package/template/src/app/(auth)/layout.tsx +71 -0
- package/template/src/app/(editor)/EditorToast.tsx +43 -0
- package/template/src/app/(editor)/edit/[id]/PageEditor.tsx +586 -0
- package/template/src/app/(editor)/edit/[id]/actions.ts +139 -0
- package/template/src/app/(editor)/edit/[id]/page.tsx +76 -0
- package/template/src/app/(editor)/edit/[id]/preview/page.tsx +81 -0
- package/template/src/app/(editor)/edit/email/[id]/EmailEditor.tsx +236 -0
- package/template/src/app/(editor)/edit/email/[id]/page.tsx +64 -0
- package/template/src/app/(editor)/edit/theme-preview/page.tsx +94 -0
- package/template/src/app/(editor)/editor.css +223 -0
- package/template/src/app/(editor)/error.tsx +32 -0
- package/template/src/app/(editor)/layout.tsx +67 -0
- package/template/src/app/(frontend)/[slug]/page.tsx +53 -0
- package/template/src/app/(frontend)/fonts.ts +8 -0
- package/template/src/app/(frontend)/layout.tsx +107 -0
- package/template/src/app/(frontend)/not-found.tsx +16 -0
- package/template/src/app/(frontend)/page.tsx +42 -0
- package/template/src/app/(frontend)/pets/[slug]/page.tsx +92 -0
- package/template/src/app/(frontend)/pets/page.tsx +42 -0
- package/template/src/app/(frontend)/styles.css +537 -0
- package/template/src/app/(setup)/error.tsx +9 -0
- package/template/src/app/(setup)/layout.tsx +41 -0
- package/template/src/app/(setup)/setup/page.tsx +105 -0
- package/template/src/app/(setup)/setup/storage-check.ts +43 -0
- package/template/src/app/api/auth/[...all]/route.ts +144 -0
- package/template/src/app/health/route.ts +9 -0
- package/template/src/app/media/[...path]/route.ts +45 -0
- package/template/src/app/media/email/[name]/route.ts +60 -0
- package/template/src/app/robots.ts +19 -0
- package/template/src/app/sitemap.ts +24 -0
- package/template/src/components/admin/AdminNav.tsx +153 -0
- package/template/src/components/admin/AdminShell.tsx +107 -0
- package/template/src/components/admin/DemoNotice.tsx +31 -0
- package/template/src/components/admin/EmailConfirmBanner.tsx +44 -0
- package/template/src/components/admin/EmptyState.tsx +10 -0
- package/template/src/components/admin/ErrorSummary.tsx +72 -0
- package/template/src/components/admin/MediaDetails.tsx +218 -0
- package/template/src/components/admin/MediaGrid.tsx +307 -0
- package/template/src/components/admin/MediaLibrary.tsx +103 -0
- package/template/src/components/admin/MediaPager.tsx +66 -0
- package/template/src/components/admin/PageHeader.tsx +22 -0
- package/template/src/components/admin/PhoneInput.tsx +128 -0
- package/template/src/components/admin/PluginWidgetBoundary.tsx +38 -0
- package/template/src/components/admin/PluginWidgets.tsx +51 -0
- package/template/src/components/admin/RemountOnNavigate.tsx +37 -0
- package/template/src/components/admin/StatusBadge.tsx +16 -0
- package/template/src/components/admin/UploadPhotosDialog.tsx +387 -0
- package/template/src/components/admin/UserAvatar.tsx +18 -0
- package/template/src/components/admin/UserMenu.tsx +118 -0
- package/template/src/components/admin/ViewSiteLink.tsx +24 -0
- package/template/src/components/admin/account/ConnectedProviders.tsx +91 -0
- package/template/src/components/admin/account/DeleteAccountCard.tsx +136 -0
- package/template/src/components/admin/account/EmailCard.tsx +137 -0
- package/template/src/components/admin/account/ProfilePicture.tsx +159 -0
- package/template/src/components/admin/activity/ActivityFilters.tsx +146 -0
- package/template/src/components/admin/activity/ActivityLog.tsx +159 -0
- package/template/src/components/admin/activity/RecentActivity.tsx +52 -0
- package/template/src/components/admin/demo-mode.tsx +17 -0
- package/template/src/components/admin/nav-items.ts +47 -0
- package/template/src/components/admin/pages/PageDetails.tsx +198 -0
- package/template/src/components/admin/pages/PageVersions.tsx +296 -0
- package/template/src/components/admin/pages/PagesTable.tsx +467 -0
- package/template/src/components/admin/pets/FilterBar.tsx +154 -0
- package/template/src/components/admin/pets/PetCard.tsx +170 -0
- package/template/src/components/admin/pets/PetList.tsx +112 -0
- package/template/src/components/admin/pets/PetListSkeleton.tsx +84 -0
- package/template/src/components/admin/pets/PetPagination.tsx +91 -0
- package/template/src/components/admin/pets/form/AgeFields.tsx +132 -0
- package/template/src/components/admin/pets/form/LocationFields.tsx +231 -0
- package/template/src/components/admin/pets/form/MediaPickerDialog.tsx +359 -0
- package/template/src/components/admin/pets/form/PhotosField.tsx +176 -0
- package/template/src/components/admin/pets/form/RichTextField.tsx +438 -0
- package/template/src/components/admin/pets/form/SeoImageField.tsx +87 -0
- package/template/src/components/admin/pets/form/SeoPreview.tsx +142 -0
- package/template/src/components/admin/pets/form/fields.tsx +434 -0
- package/template/src/components/admin/pets/form/rich-text-extensions.ts +45 -0
- package/template/src/components/admin/pets/timeline/PetTimeline.tsx +297 -0
- package/template/src/components/admin/pets/timeline/TimelineEntryForm.tsx +289 -0
- package/template/src/components/admin/pets/timeline/TimelinePhotosField.tsx +173 -0
- package/template/src/components/admin/plugins/PluginNotReady.tsx +28 -0
- package/template/src/components/admin/plugins/PluginOverview.tsx +121 -0
- package/template/src/components/admin/plugins/SendTestEmail.tsx +70 -0
- package/template/src/components/admin/settings/AuthProviders.tsx +373 -0
- package/template/src/components/admin/settings/AuthenticationNav.tsx +42 -0
- package/template/src/components/admin/settings/EmailNav.tsx +40 -0
- package/template/src/components/admin/settings/EmailSettingsForm.tsx +325 -0
- package/template/src/components/admin/settings/EmailTemplates.tsx +551 -0
- package/template/src/components/admin/settings/RegionFields.tsx +203 -0
- package/template/src/components/admin/site-time.tsx +26 -0
- package/template/src/components/admin/theme/ThemeEditor.tsx +467 -0
- package/template/src/components/admin/theme/ThemeLibrary.tsx +339 -0
- package/template/src/components/admin/theme/ThemeSwatches.tsx +30 -0
- package/template/src/components/admin/theme/theme-utils.ts +32 -0
- package/template/src/components/admin/two-factor/BackupCodeList.tsx +54 -0
- package/template/src/components/admin/two-factor/TwoFactorCard.tsx +237 -0
- package/template/src/components/admin/two-factor/TwoFactorRequired.tsx +52 -0
- package/template/src/components/admin/two-factor/TwoFactorSetup.tsx +180 -0
- package/template/src/components/admin/use-unsaved-changes.tsx +101 -0
- package/template/src/components/admin/users/ArchivedAccounts.tsx +159 -0
- package/template/src/components/admin/users/InviteDialogs.tsx +131 -0
- package/template/src/components/admin/users/TwoFactorRoles.tsx +80 -0
- package/template/src/components/admin/users/UserDialogs.tsx +681 -0
- package/template/src/components/admin/users/UsersTable.tsx +374 -0
- package/template/src/components/admin/view-only.tsx +43 -0
- package/template/src/components/auth/AcceptInviteForm.tsx +123 -0
- package/template/src/components/auth/AuthNav.tsx +80 -0
- package/template/src/components/auth/ConfirmEmailForm.tsx +73 -0
- package/template/src/components/auth/LoginForm.tsx +250 -0
- package/template/src/components/auth/PageError.tsx +37 -0
- package/template/src/components/auth/ProviderSignIn.tsx +53 -0
- package/template/src/components/auth/ResetPasswordForm.tsx +267 -0
- package/template/src/components/demo/DemoBanner.tsx +38 -0
- package/template/src/components/demo/SiteDemoBanner.tsx +22 -0
- package/template/src/components/demo/wording.ts +21 -0
- package/template/src/components/setup/SetupAccountForm.tsx +93 -0
- package/template/src/components/setup/SetupDone.tsx +95 -0
- package/template/src/components/setup/SetupNav.tsx +49 -0
- package/template/src/components/setup/SetupSampleContent.tsx +67 -0
- package/template/src/components/setup/SetupSiteForm.tsx +104 -0
- package/template/src/components/setup/SetupThemePicker.tsx +73 -0
- package/template/src/components/setup/SkipSetup.tsx +35 -0
- package/template/src/components/site/BuilderContent.tsx +46 -0
- package/template/src/components/site/CopyButton.tsx +28 -0
- package/template/src/components/site/ImageCarousel.tsx +52 -0
- package/template/src/components/site/PetCard.tsx +32 -0
- package/template/src/components/site/PetCatalog.tsx +106 -0
- package/template/src/components/site/PetGallery.tsx +75 -0
- package/template/src/components/site/PetTimeline.tsx +82 -0
- package/template/src/components/site/RemountOnNavigate.tsx +13 -0
- package/template/src/components/site/RichText.tsx +56 -0
- package/template/src/components/site/SmartLink.tsx +37 -0
- package/template/src/components/site/SocialIcons.tsx +26 -0
- package/template/src/components/site/ThemePreviewBridge.tsx +29 -0
- package/template/src/components/site/ThemeStyle.tsx +22 -0
- package/template/src/components/site/ThemeToggle.tsx +36 -0
- package/template/src/components/site/WhatsAppButton.tsx +27 -0
- package/template/src/components/site/timeline-format.ts +20 -0
- package/template/src/db/client.ts +702 -0
- package/template/src/db/compare-tables.ts +41 -0
- package/template/src/db/migrate.ts +28 -0
- package/template/src/db/plugin-migrations.ts +167 -0
- package/template/src/db/schema/pg.ts +484 -0
- package/template/src/db/schema/sqlite.ts +492 -0
- package/template/src/instrumentation.ts +110 -0
- package/template/src/lib/activity.ts +29 -0
- package/template/src/lib/admin/call-action.ts +19 -0
- package/template/src/lib/admin/initials.ts +9 -0
- package/template/src/lib/admin/media-cache.ts +16 -0
- package/template/src/lib/admin/media-page.ts +3 -0
- package/template/src/lib/admin/pet-form.ts +242 -0
- package/template/src/lib/admin/pets-cache.ts +22 -0
- package/template/src/lib/admin/unwrap-client.ts +11 -0
- package/template/src/lib/admin/unwrap.ts +38 -0
- package/template/src/lib/admin/use-media-list.ts +41 -0
- package/template/src/lib/admin/use-pet-list.ts +58 -0
- package/template/src/lib/age.ts +117 -0
- package/template/src/lib/auth-provider-errors.ts +38 -0
- package/template/src/lib/cache.ts +69 -0
- package/template/src/lib/color-mode.ts +48 -0
- package/template/src/lib/demo.ts +78 -0
- package/template/src/lib/email-address.ts +9 -0
- package/template/src/lib/email-template.ts +691 -0
- package/template/src/lib/links.ts +78 -0
- package/template/src/lib/mail-error.ts +38 -0
- package/template/src/lib/media-name.ts +31 -0
- package/template/src/lib/options.ts +134 -0
- package/template/src/lib/pagination.ts +28 -0
- package/template/src/lib/pet-placeholders.ts +34 -0
- package/template/src/lib/pet-seo.ts +40 -0
- package/template/src/lib/pet-timeline.ts +62 -0
- package/template/src/lib/phone.ts +129 -0
- package/template/src/lib/places.ts +84 -0
- package/template/src/lib/queries.ts +549 -0
- package/template/src/lib/revalidate.ts +32 -0
- package/template/src/lib/rich-text.ts +215 -0
- package/template/src/lib/seo.ts +121 -0
- package/template/src/lib/slugify.ts +11 -0
- package/template/src/lib/theme.ts +546 -0
- package/template/src/lib/utils.ts +2 -0
- package/template/src/lib/whatsapp.ts +29 -0
- package/template/src/lib/zod-schema/auth.ts +56 -0
- package/template/src/lib/zod-schema/page.ts +57 -0
- package/template/src/lib/zod-schema/pet-timeline.ts +118 -0
- package/template/src/lib/zod-schema/pet.ts +172 -0
- package/template/src/lib/zod-schema/settings.ts +162 -0
- package/template/src/plugins/host.ts +117 -0
- package/template/src/plugins/icon.ts +89 -0
- package/template/src/plugins/registry.ts +369 -0
- package/template/src/plugins/storage-rules.ts +87 -0
- package/template/src/plugins/storage.ts +184 -0
- package/template/src/puck/actions.ts +46 -0
- package/template/src/puck/config.tsx +1693 -0
- package/template/src/puck/data.ts +196 -0
- package/template/src/puck/demo-mode.tsx +20 -0
- package/template/src/puck/email-config.tsx +267 -0
- package/template/src/puck/icons.tsx +76 -0
- package/template/src/puck/media-picker.tsx +273 -0
- package/template/src/puck/padding.tsx +71 -0
- package/template/src/puck/pet-page-config.tsx +511 -0
- package/template/src/puck/pet-picker.tsx +40 -0
- package/template/src/puck/plugin-block-data.ts +91 -0
- package/template/src/puck/plugin-blocks.tsx +235 -0
- package/template/src/puck/plugin-choice-field.tsx +87 -0
- package/template/src/puck/sanitize.ts +107 -0
- package/template/src/puck/server.ts +36 -0
- package/template/src/puck/types.ts +41 -0
- package/template/src/server/actions/activity.ts +48 -0
- package/template/src/server/actions/auth-providers.ts +171 -0
- package/template/src/server/actions/auth.ts +217 -0
- package/template/src/server/actions/demo.ts +30 -0
- package/template/src/server/actions/email-change.ts +80 -0
- package/template/src/server/actions/email-templates.ts +144 -0
- package/template/src/server/actions/email.ts +70 -0
- package/template/src/server/actions/media.ts +127 -0
- package/template/src/server/actions/pages.ts +159 -0
- package/template/src/server/actions/password-reset.ts +80 -0
- package/template/src/server/actions/pet-timeline.ts +75 -0
- package/template/src/server/actions/pets.ts +74 -0
- package/template/src/server/actions/places.ts +36 -0
- package/template/src/server/actions/settings.ts +29 -0
- package/template/src/server/actions/setup.ts +72 -0
- package/template/src/server/actions/themes.ts +80 -0
- package/template/src/server/actions/two-factor.ts +306 -0
- package/template/src/server/actions/users.ts +200 -0
- package/template/src/server/activity.ts +409 -0
- package/template/src/server/auth-errors.ts +17 -0
- package/template/src/server/auth-providers.ts +359 -0
- package/template/src/server/auth.ts +266 -0
- package/template/src/server/avatars.ts +263 -0
- package/template/src/server/demo-site.ts +169 -0
- package/template/src/server/email-change.ts +278 -0
- package/template/src/server/email-templates.ts +350 -0
- package/template/src/server/email.ts +442 -0
- package/template/src/server/invites.ts +143 -0
- package/template/src/server/media-url.ts +20 -0
- package/template/src/server/media.ts +236 -0
- package/template/src/server/pages.ts +812 -0
- package/template/src/server/password-reset.ts +158 -0
- package/template/src/server/pending-links.ts +46 -0
- package/template/src/server/pet-timeline.ts +181 -0
- package/template/src/server/pets.ts +555 -0
- package/template/src/server/places.ts +113 -0
- package/template/src/server/privacy.ts +21 -0
- package/template/src/server/provider-endpoints.ts +94 -0
- package/template/src/server/provider-guard.ts +157 -0
- package/template/src/server/result.ts +280 -0
- package/template/src/server/sample-content.ts +368 -0
- package/template/src/server/search-text.ts +43 -0
- package/template/src/server/secret-box.ts +38 -0
- package/template/src/server/session.ts +154 -0
- package/template/src/server/settings.ts +361 -0
- package/template/src/server/setup.ts +110 -0
- package/template/src/server/sitemap.ts +88 -0
- package/template/src/server/storage.ts +267 -0
- package/template/src/server/strip-metadata.ts +357 -0
- package/template/src/server/themes.ts +195 -0
- package/template/src/server/throttle.ts +258 -0
- package/template/src/server/two-factor-codes.ts +32 -0
- package/template/src/server/two-factor.ts +158 -0
- package/template/src/server/types.ts +198 -0
- package/template/src/server/uploads.ts +137 -0
- package/template/src/server/users.ts +500 -0
- package/template/tsconfig.json +44 -0
- package/template/ui/components.json +25 -0
- package/template/ui/package.json +12 -0
- package/template/ui/src/components/alert-dialog.tsx +187 -0
- package/template/ui/src/components/avatar.tsx +108 -0
- package/template/ui/src/components/badge.tsx +51 -0
- package/template/ui/src/components/button.tsx +57 -0
- package/template/ui/src/components/card.tsx +102 -0
- package/template/ui/src/components/carousel.tsx +245 -0
- package/template/ui/src/components/checkbox.tsx +27 -0
- package/template/ui/src/components/combobox.tsx +297 -0
- package/template/ui/src/components/dialog.tsx +159 -0
- package/template/ui/src/components/dropdown-menu.tsx +265 -0
- package/template/ui/src/components/field.tsx +238 -0
- package/template/ui/src/components/input-group.tsx +158 -0
- package/template/ui/src/components/input.tsx +19 -0
- package/template/ui/src/components/label.tsx +19 -0
- package/template/ui/src/components/pagination.tsx +127 -0
- package/template/ui/src/components/popover.tsx +89 -0
- package/template/ui/src/components/radio-group.tsx +37 -0
- package/template/ui/src/components/select.tsx +200 -0
- package/template/ui/src/components/separator.tsx +24 -0
- package/template/ui/src/components/sheet.tsx +138 -0
- package/template/ui/src/components/sidebar.tsx +723 -0
- package/template/ui/src/components/skeleton.tsx +13 -0
- package/template/ui/src/components/switch.tsx +31 -0
- package/template/ui/src/components/table.tsx +115 -0
- package/template/ui/src/components/tabs.tsx +81 -0
- package/template/ui/src/components/textarea.tsx +17 -0
- package/template/ui/src/components/toggle.tsx +44 -0
- package/template/ui/src/components/tooltip.tsx +65 -0
- package/template/ui/src/hooks/use-mobile.ts +21 -0
- package/template/ui/src/lib/utils.ts +2 -0
- package/template/ui/src/styles/globals.css +145 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// Site settings: one row that holds the brand, theme, contact details and menu.
|
|
2
|
+
import { isTimeZone } from '@pet-adopt/plugin-sdk'
|
|
3
|
+
import { eq } from 'drizzle-orm'
|
|
4
|
+
|
|
5
|
+
import { getDatabase } from '@/db/client'
|
|
6
|
+
import type * as S from '@/db/schema/sqlite'
|
|
7
|
+
import { validateLink, validateWebUrl } from '@/lib/links'
|
|
8
|
+
import { SOCIAL_PLATFORMS } from '@/lib/options'
|
|
9
|
+
import { isSystemPageSlug } from '@/puck/data'
|
|
10
|
+
import { TAGS } from '@/lib/cache'
|
|
11
|
+
import { safeRevalidate } from '@/lib/revalidate'
|
|
12
|
+
import {
|
|
13
|
+
BUTTON_OPTIONS,
|
|
14
|
+
DENSITY_OPTIONS,
|
|
15
|
+
FONT_OPTIONS,
|
|
16
|
+
PRESET_OPTIONS,
|
|
17
|
+
RADIUS_OPTIONS,
|
|
18
|
+
SHADOW_OPTIONS,
|
|
19
|
+
TEXT_SIZE_OPTIONS,
|
|
20
|
+
contrastProblem,
|
|
21
|
+
validateHexColor,
|
|
22
|
+
type Mode,
|
|
23
|
+
type ThemeSettings,
|
|
24
|
+
} from '@/lib/theme'
|
|
25
|
+
import { toE164, validatePhone } from '@/lib/phone'
|
|
26
|
+
|
|
27
|
+
import { getMediaByIds } from './media'
|
|
28
|
+
import { findPlaceCountry } from './places'
|
|
29
|
+
import { asRecord, Fields, isForeignKeyViolation, ValidationError, type FieldErrors } from './result'
|
|
30
|
+
import type { MediaItem, SiteSetting } from './types'
|
|
31
|
+
|
|
32
|
+
type SettingsRow = typeof S.siteSettings.$inferSelect
|
|
33
|
+
type CustomTheme = NonNullable<ThemeSettings['customTheme']>
|
|
34
|
+
|
|
35
|
+
const SETTINGS_ID = 1
|
|
36
|
+
/** Menu items and social links beyond this are certainly a mistake, and every one is rendered on every page. */
|
|
37
|
+
const MAX_LIST_ITEMS = 20
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_SETTINGS: SiteSetting = {
|
|
40
|
+
id: 0,
|
|
41
|
+
siteName: 'Pet Adopt',
|
|
42
|
+
tagline: 'Find your new best friend',
|
|
43
|
+
logo: null,
|
|
44
|
+
favicon: null,
|
|
45
|
+
primaryColor: null,
|
|
46
|
+
theme: 'sunrise',
|
|
47
|
+
allowModeToggle: true,
|
|
48
|
+
customize: false,
|
|
49
|
+
customTheme: null,
|
|
50
|
+
activeThemeId: null,
|
|
51
|
+
whatsappNumber: null,
|
|
52
|
+
whatsappMessage: "Hi! I'm interested in adopting {pet}.",
|
|
53
|
+
address: null,
|
|
54
|
+
openingHours: null,
|
|
55
|
+
socials: [],
|
|
56
|
+
nav: [],
|
|
57
|
+
footerText: null,
|
|
58
|
+
privacyPageId: null,
|
|
59
|
+
country: null,
|
|
60
|
+
timeZone: null,
|
|
61
|
+
updatedAt: null,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The smallest favicon accepted. Browsers show 16 to 32 px, phones' home screens up to 180. */
|
|
65
|
+
export const FAVICON_MIN_SIZE = 32
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Why an image cannot be the favicon, or null when it can. Browsers squash a non-square icon, so it
|
|
69
|
+
* must be square (within 5%, for crops that are a pixel or two off) and at least 32 px.
|
|
70
|
+
*/
|
|
71
|
+
export function faviconProblem(image: Pick<MediaItem, 'width' | 'height'> | undefined | null): string | null {
|
|
72
|
+
if (!image) return 'That image no longer exists.'
|
|
73
|
+
const { width, height } = image
|
|
74
|
+
if (!width || !height) return null
|
|
75
|
+
if (Math.abs(width - height) > Math.max(width, height) * 0.05) return `Use a square image (this one is ${width} × ${height} px).`
|
|
76
|
+
if (Math.min(width, height) < FAVICON_MIN_SIZE) return `Use an image at least ${FAVICON_MIN_SIZE} × ${FAVICON_MIN_SIZE} px (this one is ${width} × ${height} px).`
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function toSettings(row: SettingsRow, logo: SiteSetting['logo'], favicon: SiteSetting['favicon']): SiteSetting {
|
|
81
|
+
return {
|
|
82
|
+
id: row.id,
|
|
83
|
+
siteName: row.siteName,
|
|
84
|
+
tagline: row.tagline,
|
|
85
|
+
logo,
|
|
86
|
+
favicon,
|
|
87
|
+
primaryColor: row.primaryColor,
|
|
88
|
+
theme: row.theme,
|
|
89
|
+
allowModeToggle: row.allowModeToggle,
|
|
90
|
+
customize: row.customize,
|
|
91
|
+
customTheme: (row.customTheme as SiteSetting['customTheme']) ?? null,
|
|
92
|
+
activeThemeId: row.activeThemeId ?? null,
|
|
93
|
+
whatsappNumber: row.whatsappNumber,
|
|
94
|
+
whatsappMessage: row.whatsappMessage,
|
|
95
|
+
address: row.address,
|
|
96
|
+
openingHours: row.openingHours,
|
|
97
|
+
socials: row.socials ?? [],
|
|
98
|
+
nav: row.nav ?? [],
|
|
99
|
+
footerText: row.footerText,
|
|
100
|
+
privacyPageId: row.privacyPageId ?? null,
|
|
101
|
+
country: row.country ?? null,
|
|
102
|
+
timeZone: row.timeZone ?? null,
|
|
103
|
+
updatedAt: row.updatedAt,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The site settings. When the owner uses one of their saved themes, it is laid over the theme
|
|
109
|
+
* fields here (its base preset, its customisations, no separate brand colour), so everything that
|
|
110
|
+
* reads the theme (public pages, admin, page builder) needs nothing else.
|
|
111
|
+
*/
|
|
112
|
+
export async function getSettings(): Promise<SiteSetting> {
|
|
113
|
+
const { db, t } = await getDatabase()
|
|
114
|
+
const [row] = await db.select().from(t.siteSettings).where(eq(t.siteSettings.id, SETTINGS_ID)).limit(1)
|
|
115
|
+
if (!row) return DEFAULT_SETTINGS
|
|
116
|
+
const ids = [row.logoId, row.faviconId].filter((id): id is number => Boolean(id))
|
|
117
|
+
const images = ids.length ? await getMediaByIds(ids) : new Map<number, MediaItem>()
|
|
118
|
+
const image = (id: number | null) => (id ? (images.get(id) ?? null) : null)
|
|
119
|
+
const settings = toSettings(row, image(row.logoId), image(row.faviconId))
|
|
120
|
+
if (row.activeThemeId) {
|
|
121
|
+
const [theme] = await db.select().from(t.themes).where(eq(t.themes.id, row.activeThemeId)).limit(1)
|
|
122
|
+
if (theme) {
|
|
123
|
+
return {
|
|
124
|
+
...settings,
|
|
125
|
+
theme: theme.base,
|
|
126
|
+
customize: true,
|
|
127
|
+
customTheme: (theme.settings as SiteSetting['customTheme']) ?? {},
|
|
128
|
+
primaryColor: null,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return settings
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const COLOR_KEYS = ['primary', 'background', 'surface', 'text', 'tint'] as const
|
|
136
|
+
export const MODES: Mode[] = ['light', 'dark']
|
|
137
|
+
|
|
138
|
+
const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
|
139
|
+
Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
140
|
+
|
|
141
|
+
/** One set of colours. Only the keys that were sent come back; null clears the whole set. */
|
|
142
|
+
function parseColors(raw: unknown, path: string, errors: FieldErrors): Record<string, string | null> | null {
|
|
143
|
+
if (raw === null) return null
|
|
144
|
+
if (!isPlainObject(raw)) {
|
|
145
|
+
errors[path] = 'Must be an object.'
|
|
146
|
+
return {}
|
|
147
|
+
}
|
|
148
|
+
const f = new Fields(raw)
|
|
149
|
+
const colors: Record<string, string | null> = {}
|
|
150
|
+
for (const key of COLOR_KEYS) {
|
|
151
|
+
const value = f.text(key, 9, { validate: (s) => validateHexColor(s) })
|
|
152
|
+
if (value !== undefined) colors[key] = value
|
|
153
|
+
}
|
|
154
|
+
for (const [key, message] of Object.entries(f.errors)) errors[`${path}.${key}`] = message
|
|
155
|
+
return colors
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Only the keys that were sent come back, so they can be merged into what is stored. */
|
|
159
|
+
export function parseCustomTheme(raw: unknown, errors: FieldErrors): Record<string, unknown> {
|
|
160
|
+
if (!isPlainObject(raw)) {
|
|
161
|
+
errors.customTheme = 'Must be an object.'
|
|
162
|
+
return {}
|
|
163
|
+
}
|
|
164
|
+
const f = new Fields(raw)
|
|
165
|
+
const sent: Record<string, unknown> = {}
|
|
166
|
+
const selects: Array<[string, readonly { value: string }[]]> = [
|
|
167
|
+
['headingFont', FONT_OPTIONS],
|
|
168
|
+
['bodyFont', FONT_OPTIONS],
|
|
169
|
+
['radius', RADIUS_OPTIONS],
|
|
170
|
+
['button', BUTTON_OPTIONS],
|
|
171
|
+
['shadow', SHADOW_OPTIONS],
|
|
172
|
+
['density', DENSITY_OPTIONS],
|
|
173
|
+
['textSize', TEXT_SIZE_OPTIONS],
|
|
174
|
+
]
|
|
175
|
+
for (const [key, options] of selects) {
|
|
176
|
+
const value = f.oneOf(key, options)
|
|
177
|
+
if (value !== undefined) sent[key] = value
|
|
178
|
+
}
|
|
179
|
+
for (const mode of MODES) {
|
|
180
|
+
if (raw[mode] !== undefined) sent[mode] = parseColors(raw[mode], `customTheme.${mode}`, errors)
|
|
181
|
+
}
|
|
182
|
+
for (const [key, message] of Object.entries(f.errors)) errors[`customTheme.${key}`] = message
|
|
183
|
+
return sent
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* What is stored, with the keys that were sent laid over it. Sending `{ radius: 'lg' }` changes the
|
|
188
|
+
* corners and keeps every saved colour; sending a key as null clears just that one.
|
|
189
|
+
*/
|
|
190
|
+
function mergeCustomTheme(stored: SiteSetting['customTheme'], sent: Record<string, unknown>): CustomTheme {
|
|
191
|
+
const base = (stored ?? {}) as Record<string, unknown>
|
|
192
|
+
const merged: Record<string, unknown> = { ...base }
|
|
193
|
+
for (const [key, value] of Object.entries(sent)) {
|
|
194
|
+
if (MODES.includes(key as Mode)) {
|
|
195
|
+
merged[key] = value === null ? {} : { ...(isPlainObject(base[key]) ? base[key] : {}), ...(value as object) }
|
|
196
|
+
} else {
|
|
197
|
+
merged[key] = value
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return merged as CustomTheme
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Admins and developers (`settings:edit`, checked by the caller). Keys that are left out stay as
|
|
205
|
+
* they are, at every level.
|
|
206
|
+
*/
|
|
207
|
+
export async function updateSettings(raw: unknown): Promise<SiteSetting> {
|
|
208
|
+
const input = asRecord(raw)
|
|
209
|
+
const { db, t, withTransaction } = await getDatabase()
|
|
210
|
+
|
|
211
|
+
const f = new Fields(input)
|
|
212
|
+
const v: Partial<typeof S.siteSettings.$inferInsert> = {}
|
|
213
|
+
const put = <K extends keyof typeof v>(key: K, value: (typeof v)[K] | undefined) => {
|
|
214
|
+
if (value !== undefined) v[key] = value
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
put('siteName', f.requiredText('siteName', 80))
|
|
218
|
+
put('tagline', f.text('tagline', 160))
|
|
219
|
+
put('logoId', f.id('logoId'))
|
|
220
|
+
put('faviconId', f.id('faviconId'))
|
|
221
|
+
put('primaryColor', f.text('primaryColor', 9, { validate: (s) => validateHexColor(s) }))
|
|
222
|
+
put('theme', f.oneOf('theme', PRESET_OPTIONS) ?? undefined)
|
|
223
|
+
put('allowModeToggle', f.flag('allowModeToggle'))
|
|
224
|
+
put('customize', f.flag('customize'))
|
|
225
|
+
// Checked with libphonenumber and stored in E.164 ("+60123456789"); a number typed without a
|
|
226
|
+
// "+code" is read as the default country (NEXT_PUBLIC_DEFAULT_COUNTRY_CODE).
|
|
227
|
+
const whatsapp = f.text('whatsappNumber', 40, { validate: (s) => validatePhone(s) })
|
|
228
|
+
put('whatsappNumber', whatsapp ? toE164(whatsapp) : whatsapp)
|
|
229
|
+
put('whatsappMessage', f.text('whatsappMessage', 300))
|
|
230
|
+
put('address', f.text('address', 500))
|
|
231
|
+
put('openingHours', f.text('openingHours', 500))
|
|
232
|
+
put('footerText', f.text('footerText', 500))
|
|
233
|
+
put('privacyPageId', f.id('privacyPageId'))
|
|
234
|
+
// Where the site is: the country new pets start with, and the time zone the admin shows times in.
|
|
235
|
+
const country = f.text('country', 2, { validate: (s) => /^[A-Za-z]{2}$/.test(s) || 'Pick a country from the list.' })
|
|
236
|
+
put('country', country ? country.toUpperCase() : country)
|
|
237
|
+
put('timeZone', f.text('timeZone', 64, { validate: (s) => isTimeZone(s) || 'Pick a time zone from the list.' }))
|
|
238
|
+
|
|
239
|
+
const errors: FieldErrors = { ...f.errors }
|
|
240
|
+
|
|
241
|
+
// The custom theme keys that were sent; they are merged into the stored ones below.
|
|
242
|
+
const themePatch =
|
|
243
|
+
input.customTheme === undefined ? undefined : input.customTheme === null ? null : parseCustomTheme(input.customTheme, errors)
|
|
244
|
+
|
|
245
|
+
// null clears a list, like it clears any other field.
|
|
246
|
+
const list = (key: string): unknown[] | undefined => {
|
|
247
|
+
const value = input[key]
|
|
248
|
+
if (value === undefined) return undefined
|
|
249
|
+
if (value === null) return []
|
|
250
|
+
if (!Array.isArray(value)) {
|
|
251
|
+
errors[key] = 'Must be a list.'
|
|
252
|
+
return undefined
|
|
253
|
+
}
|
|
254
|
+
if (value.length > MAX_LIST_ITEMS) {
|
|
255
|
+
errors[key] = `Use at most ${MAX_LIST_ITEMS} items.`
|
|
256
|
+
return undefined
|
|
257
|
+
}
|
|
258
|
+
return value
|
|
259
|
+
}
|
|
260
|
+
const socials = list('socials')
|
|
261
|
+
if (socials) {
|
|
262
|
+
v.socials = socials.map((item, i) => {
|
|
263
|
+
const row = new Fields(asRecord(item), true)
|
|
264
|
+
const platform = row.oneOf('platform', SOCIAL_PLATFORMS, { required: true })
|
|
265
|
+
const url = row.requiredText('url', 300, { validate: (s) => validateWebUrl(s) })
|
|
266
|
+
for (const [key, message] of Object.entries(row.errors)) errors[`socials.${i}.${key}`] = message
|
|
267
|
+
return { platform: platform ?? '', url: url ?? '' }
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
const nav = list('nav')
|
|
271
|
+
if (nav) {
|
|
272
|
+
v.nav = nav.map((item, i) => {
|
|
273
|
+
const row = new Fields(asRecord(item), true)
|
|
274
|
+
const label = row.requiredText('label', 40)
|
|
275
|
+
const href = row.requiredText('href', 300, { validate: (s) => validateLink(s) })
|
|
276
|
+
for (const [key, message] of Object.entries(row.errors)) errors[`nav.${i}.${key}`] = message
|
|
277
|
+
return { label: label ?? '', href: href ?? '' }
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Text must stay readable on the background and on cards, in each mode. That depends on the
|
|
282
|
+
// preset, the brand colour AND the custom colours together, and changing any one of them can
|
|
283
|
+
// break a combination that was fine, so check the effective result whenever any of them is sent.
|
|
284
|
+
const checksContrast = ['theme', 'primaryColor', 'customize', 'customTheme'].some((key) => input[key] !== undefined)
|
|
285
|
+
type StoredTheme = { theme: string; primaryColor: string | null; customize: boolean; customTheme: unknown }
|
|
286
|
+
const addContrastErrors = (stored: StoredTheme | undefined) => {
|
|
287
|
+
if (!checksContrast) return
|
|
288
|
+
const customTheme =
|
|
289
|
+
themePatch === undefined
|
|
290
|
+
? stored?.customTheme
|
|
291
|
+
: themePatch === null
|
|
292
|
+
? null
|
|
293
|
+
: mergeCustomTheme(stored?.customTheme as SiteSetting['customTheme'], themePatch)
|
|
294
|
+
const effective: ThemeSettings = {
|
|
295
|
+
theme: v.theme ?? stored?.theme,
|
|
296
|
+
primaryColor: v.primaryColor !== undefined ? v.primaryColor : stored?.primaryColor,
|
|
297
|
+
customize: v.customize ?? stored?.customize ?? false,
|
|
298
|
+
customTheme: customTheme as ThemeSettings['customTheme'],
|
|
299
|
+
}
|
|
300
|
+
if (!effective.customize) return
|
|
301
|
+
for (const mode of MODES) {
|
|
302
|
+
const problem = contrastProblem(effective, mode)
|
|
303
|
+
if (problem) errors[`customTheme.${mode}.text`] ??= problem
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// A first look without the lock, so contrast problems come back with every other error in one
|
|
307
|
+
// round; the check is repeated on the locked copy below.
|
|
308
|
+
if (checksContrast) {
|
|
309
|
+
const [stored] = await db.select().from(t.siteSettings).where(eq(t.siteSettings.id, SETTINGS_ID)).limit(1)
|
|
310
|
+
addContrastErrors(stored)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (Object.keys(errors).length) throw new ValidationError(errors)
|
|
314
|
+
const chosen = [v.logoId, v.faviconId].filter((id): id is number => Boolean(id))
|
|
315
|
+
const images = chosen.length ? await getMediaByIds(chosen) : new Map<number, MediaItem>()
|
|
316
|
+
if (v.logoId && !images.has(v.logoId)) errors.logoId = 'That image no longer exists.'
|
|
317
|
+
if (v.faviconId) {
|
|
318
|
+
const problem = faviconProblem(images.get(v.faviconId))
|
|
319
|
+
if (problem) errors.faviconId = problem
|
|
320
|
+
}
|
|
321
|
+
if (v.country && !(await findPlaceCountry(v.country))) errors.country = 'Pick a country from the list.'
|
|
322
|
+
// The privacy policy must be an ordinary page of this site (not the homepage, Pets page or Pet
|
|
323
|
+
// page template) that is not archived. It may still be a draft: it is linked once it is live.
|
|
324
|
+
if (v.privacyPageId) {
|
|
325
|
+
const [page] = await db.select({ slug: t.pages.slug, archivedAt: t.pages.archivedAt }).from(t.pages).where(eq(t.pages.id, v.privacyPageId)).limit(1)
|
|
326
|
+
if (!page) errors.privacyPageId = 'That page no longer exists.'
|
|
327
|
+
else if (isSystemPageSlug(page.slug)) errors.privacyPageId = 'Choose one of your own pages, not a built-in one.'
|
|
328
|
+
else if (page.archivedAt) errors.privacyPageId = 'That page is archived. Restore it first, or choose another.'
|
|
329
|
+
}
|
|
330
|
+
if (Object.keys(errors).length) throw new ValidationError(errors)
|
|
331
|
+
|
|
332
|
+
try {
|
|
333
|
+
// One save at a time: the custom theme is merged into the stored copy, so two saves at once
|
|
334
|
+
// would both start from the same copy and the later one would drop the other's keys.
|
|
335
|
+
await withTransaction(
|
|
336
|
+
async (tx) => {
|
|
337
|
+
const [stored] = await tx.select().from(t.siteSettings).where(eq(t.siteSettings.id, SETTINGS_ID)).limit(1)
|
|
338
|
+
if (themePatch !== undefined) {
|
|
339
|
+
v.customTheme = themePatch === null ? null : mergeCustomTheme(stored?.customTheme as SiteSetting['customTheme'], themePatch)
|
|
340
|
+
}
|
|
341
|
+
addContrastErrors(stored)
|
|
342
|
+
if (Object.keys(errors).length) throw new ValidationError(errors)
|
|
343
|
+
|
|
344
|
+
await tx.insert(t.siteSettings).values({ id: SETTINGS_ID }).onConflictDoNothing()
|
|
345
|
+
await tx.update(t.siteSettings).set({ ...v, updatedAt: new Date() }).where(eq(t.siteSettings.id, SETTINGS_ID))
|
|
346
|
+
},
|
|
347
|
+
{ lock: 'site-settings' },
|
|
348
|
+
)
|
|
349
|
+
} catch (error) {
|
|
350
|
+
// The logo, site icon or privacy page was deleted after the checks above.
|
|
351
|
+
if (!isForeignKeyViolation(error)) throw error
|
|
352
|
+
const gone: FieldErrors = {}
|
|
353
|
+
if (v.logoId) gone.logoId = 'That image no longer exists.'
|
|
354
|
+
if (v.faviconId) gone.faviconId = 'That image no longer exists.'
|
|
355
|
+
if (v.privacyPageId) gone.privacyPageId = 'That page no longer exists.'
|
|
356
|
+
if (!Object.keys(gone).length) throw error
|
|
357
|
+
throw new ValidationError(gone)
|
|
358
|
+
}
|
|
359
|
+
safeRevalidate([['/', 'layout']], [TAGS.settings])
|
|
360
|
+
return getSettings()
|
|
361
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// First-time setup (agreed with the owner). A new site has no accounts; the first one is made on the
|
|
2
|
+
// setup page (/setup), then a guided setup offers the site's basics, a theme, sample content and
|
|
3
|
+
// email, each skippable, until it is finished or skipped (`site_settings.setup_done_at`).
|
|
4
|
+
//
|
|
5
|
+
// Claiming a new site: whoever reaches a fresh deployment first must not become its admin. So the
|
|
6
|
+
// setup page only works with a link printed in the server's log: `<site>/setup?key=<32 random
|
|
7
|
+
// bytes>`. The key is made once and kept sealed in `site_settings.setup_key_encrypted` (secret-box),
|
|
8
|
+
// so every server instance prints the same link; it is deleted when the first account exists.
|
|
9
|
+
//
|
|
10
|
+
// Unattended installs can still set SEED_ADMIN_EMAIL / SEED_ADMIN_PASSWORD (users.ensureOwner): the
|
|
11
|
+
// account step is then done already and the guided setup starts at the site's basics.
|
|
12
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto'
|
|
13
|
+
|
|
14
|
+
import { and, count, eq, isNull } from 'drizzle-orm'
|
|
15
|
+
|
|
16
|
+
import { getDatabase } from '@/db/client'
|
|
17
|
+
|
|
18
|
+
import { SITE_URL } from './auth'
|
|
19
|
+
import { UserError } from './result'
|
|
20
|
+
import { open, seal } from './secret-box'
|
|
21
|
+
import { createUser } from './users'
|
|
22
|
+
|
|
23
|
+
const SETTINGS_ID = 1
|
|
24
|
+
const KEY_PURPOSE = 'setup-key'
|
|
25
|
+
/** 32 random bytes in base64url. */
|
|
26
|
+
const KEY = /^[A-Za-z0-9_-]{43}$/
|
|
27
|
+
|
|
28
|
+
export const setupUrl = (key: string) => `${SITE_URL}/setup?key=${key}`
|
|
29
|
+
|
|
30
|
+
/** Whether any account exists (then the setup link is gone for good). */
|
|
31
|
+
export async function hasAccounts(): Promise<boolean> {
|
|
32
|
+
const { db, t } = await getDatabase()
|
|
33
|
+
const [row] = await db.select({ n: count() }).from(t.users)
|
|
34
|
+
return row.n > 0
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Whether the guided setup was finished or skipped. */
|
|
38
|
+
export async function isSetupDone(): Promise<boolean> {
|
|
39
|
+
const { db, t } = await getDatabase()
|
|
40
|
+
const [row] = await db.select({ done: t.siteSettings.setupDoneAt }).from(t.siteSettings).where(eq(t.siteSettings.id, SETTINGS_ID)).limit(1)
|
|
41
|
+
return Boolean(row?.done)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The setup link while no account exists (null once one does). Made once and stored sealed, so
|
|
46
|
+
* every instance of the site prints the same link; the first one to start makes it.
|
|
47
|
+
*/
|
|
48
|
+
export async function ensureSetupLink(): Promise<string | null> {
|
|
49
|
+
if (await hasAccounts()) return null
|
|
50
|
+
const { db, t } = await getDatabase()
|
|
51
|
+
await db.insert(t.siteSettings).values({ id: SETTINGS_ID }).onConflictDoNothing()
|
|
52
|
+
// Only fills an empty slot: two instances starting together keep whichever key was written first.
|
|
53
|
+
await db
|
|
54
|
+
.update(t.siteSettings)
|
|
55
|
+
.set({ setupKeyEncrypted: seal(randomBytes(32).toString('base64url'), KEY_PURPOSE) })
|
|
56
|
+
.where(and(eq(t.siteSettings.id, SETTINGS_ID), isNull(t.siteSettings.setupKeyEncrypted)))
|
|
57
|
+
const key = await storedKey()
|
|
58
|
+
if (key) return setupUrl(key)
|
|
59
|
+
// Sealed with another BETTER_AUTH_SECRET: make a new one.
|
|
60
|
+
await db.update(t.siteSettings).set({ setupKeyEncrypted: null }).where(eq(t.siteSettings.id, SETTINGS_ID))
|
|
61
|
+
return ensureSetupLink()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function storedKey(): Promise<string | null> {
|
|
65
|
+
const { db, t } = await getDatabase()
|
|
66
|
+
const [row] = await db.select({ sealed: t.siteSettings.setupKeyEncrypted }).from(t.siteSettings).where(eq(t.siteSettings.id, SETTINGS_ID)).limit(1)
|
|
67
|
+
return open(row?.sealed, KEY_PURPOSE)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Whether `key` is the setup link's key, while no account exists. Compared in constant time. */
|
|
71
|
+
export async function isSetupKeyValid(key: unknown): Promise<boolean> {
|
|
72
|
+
if (typeof key !== 'string' || !KEY.test(key) || (await hasAccounts())) return false
|
|
73
|
+
const stored = await storedKey()
|
|
74
|
+
return Boolean(stored) && timingSafeEqual(Buffer.from(stored as string), Buffer.from(key))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Prints the setup link to the server log in a box people notice. */
|
|
78
|
+
export function announceSetupLink(link: string): void {
|
|
79
|
+
const lines = ['This site has no accounts yet. Open this link to create the first admin account:', link, 'Only someone who can read this log has it. It stops working once the account exists.']
|
|
80
|
+
const width = Math.max(...lines.map((line) => line.length))
|
|
81
|
+
const rule = `+${'-'.repeat(width + 2)}+`
|
|
82
|
+
console.log(['', rule, ...lines.map((line) => `| ${line.padEnd(width)} |`), rule, ''].join('\n'))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Creates the first account, an admin, with the setup link's key: `{ name, email, password }`.
|
|
87
|
+
* Refused once any account exists; two people at once cannot both succeed (one lock, then the
|
|
88
|
+
* count). The key is deleted with it.
|
|
89
|
+
*/
|
|
90
|
+
export async function createFirstAdmin(key: unknown, input: unknown): Promise<{ id: string }> {
|
|
91
|
+
if (!(await isSetupKeyValid(key))) throw new UserError('This setup link no longer works. If the site is already set up, sign in instead.')
|
|
92
|
+
const { t, withTransaction } = await getDatabase()
|
|
93
|
+
return withTransaction(
|
|
94
|
+
async (tx) => {
|
|
95
|
+
const [row] = await tx.select({ n: count() }).from(t.users)
|
|
96
|
+
if (row.n > 0) throw new UserError('This site already has an account. Sign in instead.')
|
|
97
|
+
const created = await createUser({ ...(input as object), role: 'admin' })
|
|
98
|
+
await tx.update(t.siteSettings).set({ setupKeyEncrypted: null, updatedAt: new Date() }).where(eq(t.siteSettings.id, SETTINGS_ID))
|
|
99
|
+
return created
|
|
100
|
+
},
|
|
101
|
+
{ lock: 'setup:first-account' },
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Ends the guided setup (finished or skipped); it is not shown again. */
|
|
106
|
+
export async function finishSetup(): Promise<void> {
|
|
107
|
+
const { db, t } = await getDatabase()
|
|
108
|
+
await db.insert(t.siteSettings).values({ id: SETTINGS_ID }).onConflictDoNothing()
|
|
109
|
+
await db.update(t.siteSettings).set({ setupDoneAt: new Date(), updatedAt: new Date() }).where(eq(t.siteSettings.id, SETTINGS_ID))
|
|
110
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// sitemap.xml (agreed with the owner): what search engines should find. The homepage and the Pets
|
|
2
|
+
// page, every live page of the owners' own (not archived; never the Pet page template, which has no
|
|
3
|
+
// address), and every listed pet that is not adopted, with its main photo for image search. Adopted
|
|
4
|
+
// pets stay out (searches should favour pets that can be adopted) but their pages stay indexable.
|
|
5
|
+
// Unlisted pets are link-only and never listed.
|
|
6
|
+
import { and, asc, eq, isNotNull, isNull, ne, notInArray } from 'drizzle-orm'
|
|
7
|
+
import type { MetadataRoute } from 'next'
|
|
8
|
+
|
|
9
|
+
import { getDatabase } from '@/db/client'
|
|
10
|
+
import { PetStatus } from '@/lib/options'
|
|
11
|
+
import { absoluteUrl } from '@/lib/seo'
|
|
12
|
+
import { PET_PAGE_SLUG } from '@/puck/data'
|
|
13
|
+
|
|
14
|
+
import { mediaUrl } from './media-url'
|
|
15
|
+
|
|
16
|
+
/** A sitemap file may list at most this many addresses. */
|
|
17
|
+
const MAX_URLS = 50_000
|
|
18
|
+
|
|
19
|
+
export async function sitemapEntries(): Promise<MetadataRoute.Sitemap> {
|
|
20
|
+
const { db, t } = await getDatabase()
|
|
21
|
+
const [pages, pets] = await Promise.all([
|
|
22
|
+
db
|
|
23
|
+
.select({ slug: t.pages.slug, publishedAt: t.pages.publishedAt, updatedAt: t.pages.updatedAt })
|
|
24
|
+
.from(t.pages)
|
|
25
|
+
.where(and(eq(t.pages.status, 'published'), isNull(t.pages.archivedAt), notInArray(t.pages.slug, [PET_PAGE_SLUG])))
|
|
26
|
+
.orderBy(asc(t.pages.slug)),
|
|
27
|
+
// Each pet with its main photo (position 0), if it has one.
|
|
28
|
+
db
|
|
29
|
+
.select({ slug: t.pets.slug, updatedAt: t.pets.updatedAt, photo: t.media.filename })
|
|
30
|
+
.from(t.pets)
|
|
31
|
+
.leftJoin(t.petPhotos, and(eq(t.petPhotos.petId, t.pets.id), eq(t.petPhotos.position, 0)))
|
|
32
|
+
.leftJoin(t.media, eq(t.media.id, t.petPhotos.mediaId))
|
|
33
|
+
.where(and(eq(t.pets.unlisted, false), ne(t.pets.status, PetStatus.Adopted)))
|
|
34
|
+
.orderBy(asc(t.pets.slug))
|
|
35
|
+
.limit(MAX_URLS),
|
|
36
|
+
])
|
|
37
|
+
|
|
38
|
+
const byPath = new Map(pages.map((page) => [page.slug, page]))
|
|
39
|
+
const lastOf = (page: { publishedAt: Date | null; updatedAt: Date } | undefined) => page?.publishedAt ?? page?.updatedAt
|
|
40
|
+
const home = byPath.get('home')
|
|
41
|
+
const petsPage = byPath.get('pets')
|
|
42
|
+
const entries: MetadataRoute.Sitemap = [
|
|
43
|
+
// The homepage and the Pets page always exist (their built-in layouts while unpublished).
|
|
44
|
+
{ url: absoluteUrl('/'), ...(lastOf(home) ? { lastModified: lastOf(home) } : {}), changeFrequency: 'weekly', priority: 1 },
|
|
45
|
+
{ url: absoluteUrl('/pets'), ...(lastOf(petsPage) ? { lastModified: lastOf(petsPage) } : {}), changeFrequency: 'daily', priority: 0.9 },
|
|
46
|
+
...pages
|
|
47
|
+
.filter((page) => page.slug !== 'home' && page.slug !== 'pets')
|
|
48
|
+
.map((page) => ({ url: absoluteUrl(`/${page.slug}`), lastModified: lastOf(page), changeFrequency: 'monthly' as const, priority: 0.5 })),
|
|
49
|
+
...pets.map((pet) => ({
|
|
50
|
+
url: absoluteUrl(`/pets/${pet.slug}`),
|
|
51
|
+
lastModified: pet.updatedAt,
|
|
52
|
+
changeFrequency: 'weekly' as const,
|
|
53
|
+
priority: 0.8,
|
|
54
|
+
...(pet.photo ? { images: [absoluteUrl(mediaUrl(pet.photo))] } : {}),
|
|
55
|
+
})),
|
|
56
|
+
]
|
|
57
|
+
return entries.slice(0, MAX_URLS)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// One real address of each kind, for generateStaticParams (src/lib/queries.ts onePetSlug,
|
|
61
|
+
// oneBuilderPageSlug): the build then renders a real pet page and a real builder page and catches
|
|
62
|
+
// mistakes on that path. Plain lookups with no clock (pet summaries read today's date for ages).
|
|
63
|
+
|
|
64
|
+
/** One listed pet's slug (the oldest), or null when there is none. */
|
|
65
|
+
export async function anyPublicPetSlug(): Promise<string | null> {
|
|
66
|
+
const { db, t } = await getDatabase()
|
|
67
|
+
const [row] = await db.select({ slug: t.pets.slug }).from(t.pets).where(eq(t.pets.unlisted, false)).orderBy(asc(t.pets.id)).limit(1)
|
|
68
|
+
return row?.slug || null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One live page of the owners' own (never the homepage, the Pets page or the Pet page template), or null. */
|
|
72
|
+
export async function anyPublicPageSlug(): Promise<string | null> {
|
|
73
|
+
const { db, t } = await getDatabase()
|
|
74
|
+
const [row] = await db
|
|
75
|
+
.select({ slug: t.pages.slug })
|
|
76
|
+
.from(t.pages)
|
|
77
|
+
.where(
|
|
78
|
+
and(
|
|
79
|
+
eq(t.pages.status, 'published'),
|
|
80
|
+
isNull(t.pages.archivedAt),
|
|
81
|
+
isNotNull(t.pages.puckPublished),
|
|
82
|
+
notInArray(t.pages.slug, ['home', 'pets', PET_PAGE_SLUG]),
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
.orderBy(asc(t.pages.id))
|
|
86
|
+
.limit(1)
|
|
87
|
+
return row?.slug || null
|
|
88
|
+
}
|