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,263 @@
|
|
|
1
|
+
// Profile pictures (agreed with the owner): each person uploads their own on the Account page, picks
|
|
2
|
+
// a square with the crop tool, and the server keeps only that square at AVATAR_SIZE px (WebP, no
|
|
3
|
+
// metadata; the original is not kept). They are not in the Media library. Admins can remove someone's
|
|
4
|
+
// picture (Users) but not upload one for them. Someone with no picture who connects a sign-in
|
|
5
|
+
// provider gets the provider's picture (from its verified ID token), copied here the same way.
|
|
6
|
+
//
|
|
7
|
+
// Files are `avatar-<32 hex>.webp` in the uploads bucket, served by /media like uploads (names are
|
|
8
|
+
// random); `users.image` holds the /media address. Replacing or removing one deletes the old file,
|
|
9
|
+
// and so does deleting the account.
|
|
10
|
+
import { randomBytes } from 'node:crypto'
|
|
11
|
+
import { lookup } from 'node:dns/promises'
|
|
12
|
+
import { get as httpsGet } from 'node:https'
|
|
13
|
+
import { BlockList, isIP } from 'node:net'
|
|
14
|
+
|
|
15
|
+
import { eq } from 'drizzle-orm'
|
|
16
|
+
import sharp, { type Metadata } from 'sharp'
|
|
17
|
+
|
|
18
|
+
import { getDatabase } from '@/db/client'
|
|
19
|
+
|
|
20
|
+
import { MEDIA_PATH, mediaUrl } from './media-url'
|
|
21
|
+
import { isValidationError, logError, ValidationError } from './result'
|
|
22
|
+
import { getStorage } from './storage'
|
|
23
|
+
|
|
24
|
+
export const AVATAR_SIZE = 256
|
|
25
|
+
const MAX_BYTES = 10_000_000
|
|
26
|
+
const MAX_PIXELS = 40_000_000
|
|
27
|
+
const MAX_SIDE = 12_000
|
|
28
|
+
const FORMATS = new Set(['jpeg', 'png', 'webp', 'gif'])
|
|
29
|
+
const AVATAR_NAME = /^avatar-[a-f0-9]{32}\.webp$/
|
|
30
|
+
|
|
31
|
+
/** The square to keep, in pixels of the (upright) picture: left, top and side. */
|
|
32
|
+
export type Crop = { x: number; y: number; size: number }
|
|
33
|
+
|
|
34
|
+
/** Reads and checks an image like any upload: JPEG, PNG, WebP or GIF, at most 10 MB and 40 megapixels. */
|
|
35
|
+
async function readImage(data: Buffer): Promise<{ meta: Metadata; width: number; height: number }> {
|
|
36
|
+
if (!data.length) throw new ValidationError({ file: 'Choose a picture.' })
|
|
37
|
+
if (data.length > MAX_BYTES) throw new ValidationError({ file: 'The picture is larger than 10 MB.' })
|
|
38
|
+
let meta: Metadata
|
|
39
|
+
try {
|
|
40
|
+
meta = await sharp(data, { limitInputPixels: MAX_PIXELS }).metadata()
|
|
41
|
+
} catch {
|
|
42
|
+
throw new ValidationError({ file: 'This file is not a readable picture, or it is too large.' })
|
|
43
|
+
}
|
|
44
|
+
if (!meta.format || !FORMATS.has(meta.format)) {
|
|
45
|
+
throw new ValidationError({ file: meta.format === 'heif' ? 'AVIF and HEIC pictures are not accepted. Use a JPEG, PNG or WebP.' : 'Use a JPEG, PNG, WebP or GIF picture.' })
|
|
46
|
+
}
|
|
47
|
+
if (!meta.width || !meta.height || meta.width > MAX_SIDE || meta.height > MAX_SIDE) throw new ValidationError({ file: 'The picture is too large.' })
|
|
48
|
+
// The crop is chosen on the picture as the browser shows it: upright, after the EXIF orientation.
|
|
49
|
+
const turned = (meta.orientation ?? 1) >= 5
|
|
50
|
+
return { meta, width: turned ? meta.height : meta.width, height: turned ? meta.width : meta.height }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A crop inside the picture, whole pixels, at least 16 px. Out-of-range values are refused, not clamped. */
|
|
54
|
+
function checkCrop(raw: unknown, width: number, height: number): Crop {
|
|
55
|
+
const { x, y, size } = (raw ?? {}) as Record<string, unknown>
|
|
56
|
+
const whole = (value: unknown) => (typeof value === 'number' && Number.isInteger(value) ? value : NaN)
|
|
57
|
+
const crop = { x: whole(x), y: whole(y), size: whole(size) }
|
|
58
|
+
if (![crop.x, crop.y, crop.size].every(Number.isFinite) || crop.x < 0 || crop.y < 0 || crop.size < 16 || crop.x + crop.size > width || crop.y + crop.size > height) {
|
|
59
|
+
throw new ValidationError({ crop: 'Pick the part of the picture to use again.' })
|
|
60
|
+
}
|
|
61
|
+
return crop
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The centre square of a picture (for provider pictures, which come without a crop). */
|
|
65
|
+
const centre = (width: number, height: number): Crop => {
|
|
66
|
+
const size = Math.min(width, height)
|
|
67
|
+
return { x: Math.floor((width - size) / 2), y: Math.floor((height - size) / 2), size }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Cuts the square out of the upright first frame and makes the small WebP (no metadata). */
|
|
71
|
+
async function render(data: Buffer, crop: Crop): Promise<Buffer> {
|
|
72
|
+
return sharp(data, { limitInputPixels: MAX_PIXELS, pages: 1 })
|
|
73
|
+
.rotate()
|
|
74
|
+
.extract({ left: crop.x, top: crop.y, width: crop.size, height: crop.size })
|
|
75
|
+
.resize(AVATAR_SIZE, AVATAR_SIZE)
|
|
76
|
+
.webp({ quality: 85 })
|
|
77
|
+
.toBuffer()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const fileOf = (image: string | null | undefined): string | null => {
|
|
81
|
+
const name = image?.startsWith(MEDIA_PATH) ? image.slice(MEDIA_PATH.length) : null
|
|
82
|
+
return name && AVATAR_NAME.test(name) ? name : null
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Deletes a stored avatar file; logs (never throws) when it cannot. */
|
|
86
|
+
export async function deleteAvatarFile(image: string | null | undefined): Promise<void> {
|
|
87
|
+
const name = fileOf(image)
|
|
88
|
+
if (!name) return
|
|
89
|
+
try {
|
|
90
|
+
await (await getStorage()).delete(name)
|
|
91
|
+
} catch (error) {
|
|
92
|
+
logError(error, `could not delete the profile picture ${name}`)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function store(userId: string, picture: Buffer): Promise<string> {
|
|
97
|
+
const name = `avatar-${randomBytes(16).toString('hex')}.webp`
|
|
98
|
+
await (await getStorage()).put(name, picture, 'image/webp')
|
|
99
|
+
const { db, t } = await getDatabase()
|
|
100
|
+
const [before] = await db.select({ image: t.users.image }).from(t.users).where(eq(t.users.id, userId)).limit(1)
|
|
101
|
+
const url = mediaUrl(name)
|
|
102
|
+
await db.update(t.users).set({ image: url, updatedAt: new Date() }).where(eq(t.users.id, userId))
|
|
103
|
+
await deleteAvatarFile(before?.image)
|
|
104
|
+
return url
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Saves an uploaded picture, cropped to `crop`, as the person's avatar. Returns its address. */
|
|
108
|
+
export async function saveAvatar(userId: string, data: Buffer, crop: unknown): Promise<string> {
|
|
109
|
+
const { width, height } = await readImage(data)
|
|
110
|
+
return store(userId, await render(data, checkCrop(crop, width, height)))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Removes a person's picture (they go back to their initials). */
|
|
114
|
+
export async function removeAvatar(userId: string): Promise<boolean> {
|
|
115
|
+
const { db, t } = await getDatabase()
|
|
116
|
+
const [user] = await db.select({ image: t.users.image }).from(t.users).where(eq(t.users.id, userId)).limit(1)
|
|
117
|
+
if (!user?.image) return false
|
|
118
|
+
await db.update(t.users).set({ image: null, updatedAt: new Date() }).where(eq(t.users.id, userId))
|
|
119
|
+
await deleteAvatarFile(user.image)
|
|
120
|
+
return true
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// --- A sign-in provider's picture ----------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
// Addresses that are not on the public internet. An IPv4 address written as IPv6 ("::ffff:10.0.0.1",
|
|
126
|
+
// also in its hex form "::ffff:a00:1") is checked against the IPv4 rules by BlockList itself.
|
|
127
|
+
const notPublic = new BlockList()
|
|
128
|
+
for (const [network, prefix] of [
|
|
129
|
+
['0.0.0.0', 8], // "this network"
|
|
130
|
+
['10.0.0.0', 8], // private
|
|
131
|
+
['100.64.0.0', 10], // carrier-grade NAT
|
|
132
|
+
['127.0.0.0', 8], // loopback
|
|
133
|
+
['169.254.0.0', 16], // link-local (cloud metadata services live here)
|
|
134
|
+
['172.16.0.0', 12], // private
|
|
135
|
+
['192.0.0.0', 24], // protocol assignments
|
|
136
|
+
['192.0.2.0', 24], // documentation
|
|
137
|
+
['192.168.0.0', 16], // private
|
|
138
|
+
['198.18.0.0', 15], // benchmarking
|
|
139
|
+
['198.51.100.0', 24], // documentation
|
|
140
|
+
['203.0.113.0', 24], // documentation
|
|
141
|
+
['224.0.0.0', 3], // multicast and reserved
|
|
142
|
+
] as const) {
|
|
143
|
+
notPublic.addSubnet(network, prefix, 'ipv4')
|
|
144
|
+
}
|
|
145
|
+
for (const [network, prefix] of [
|
|
146
|
+
['::', 96], // unspecified, loopback and the old IPv4-compatible form
|
|
147
|
+
['64:ff9b::', 96], // NAT64: an IPv4 address behind a translator
|
|
148
|
+
['2001:db8::', 32], // documentation
|
|
149
|
+
['2002::', 16], // 6to4: carries an IPv4 address
|
|
150
|
+
['fc00::', 7], // unique local
|
|
151
|
+
['fe80::', 10], // link-local
|
|
152
|
+
['fec0::', 10], // site-local (deprecated)
|
|
153
|
+
['ff00::', 8], // multicast
|
|
154
|
+
] as const) {
|
|
155
|
+
notPublic.addSubnet(network, prefix, 'ipv6')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** True for addresses that are not on the public internet (loopback, private, link-local...), and for anything that is not an address. */
|
|
159
|
+
export function isPrivateAddress(address: string): boolean {
|
|
160
|
+
const family = isIP(address)
|
|
161
|
+
if (family === 0) return true
|
|
162
|
+
return notPublic.check(address, family === 4 ? 'ipv4' : 'ipv6')
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const DOWNLOAD_LIMIT = 5_000_000
|
|
166
|
+
const DOWNLOAD_MS = 5000
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Downloads a picture from a provider's profile, carefully: https only, a public host (the address
|
|
170
|
+
* comes from whoever owns the provider account), no redirects, 5 seconds, 5 MB. Null when unsuitable.
|
|
171
|
+
*
|
|
172
|
+
* The host name is resolved once, every address it has must be public, and the connection is then
|
|
173
|
+
* made to that checked address (the certificate is still verified against the name). Resolving
|
|
174
|
+
* again for the connection would let a name answer "public" for the check and "internal" a moment
|
|
175
|
+
* later.
|
|
176
|
+
*/
|
|
177
|
+
async function download(url: string): Promise<Buffer | null> {
|
|
178
|
+
let parsed: URL
|
|
179
|
+
try {
|
|
180
|
+
parsed = new URL(url)
|
|
181
|
+
} catch {
|
|
182
|
+
return null
|
|
183
|
+
}
|
|
184
|
+
if (parsed.protocol !== 'https:' || parsed.username || parsed.password) return null
|
|
185
|
+
const addresses = await lookup(parsed.hostname.replace(/^\[|\]$/g, ''), { all: true }).catch(() => [])
|
|
186
|
+
if (!addresses.length || addresses.some((entry) => isPrivateAddress(entry.address))) return null
|
|
187
|
+
const [target] = addresses
|
|
188
|
+
|
|
189
|
+
return new Promise<Buffer | null>((resolve) => {
|
|
190
|
+
let settled = false
|
|
191
|
+
const finish = (result: Buffer | null) => {
|
|
192
|
+
if (settled) return
|
|
193
|
+
settled = true
|
|
194
|
+
clearTimeout(timer)
|
|
195
|
+
request.destroy()
|
|
196
|
+
resolve(result)
|
|
197
|
+
}
|
|
198
|
+
const request = httpsGet(
|
|
199
|
+
parsed,
|
|
200
|
+
{
|
|
201
|
+
// Connect to the address that was checked, whatever the name resolves to by now.
|
|
202
|
+
lookup: (_host, options, callback) => {
|
|
203
|
+
const all = typeof options === 'object' && options !== null && (options as { all?: boolean }).all
|
|
204
|
+
if (all) (callback as unknown as (error: null, list: Array<{ address: string; family: number }>) => void)(null, [target])
|
|
205
|
+
else callback(null, target.address, target.family)
|
|
206
|
+
},
|
|
207
|
+
// The same plain client name Node's own fetch sends; some hosts refuse a request without one.
|
|
208
|
+
headers: { accept: 'image/*', 'user-agent': 'node' },
|
|
209
|
+
},
|
|
210
|
+
(response) => {
|
|
211
|
+
// No redirects: 3xx is simply not a picture.
|
|
212
|
+
if (response.statusCode !== 200) return finish(null)
|
|
213
|
+
if (Number(response.headers['content-length'] ?? 0) > DOWNLOAD_LIMIT) return finish(null)
|
|
214
|
+
const chunks: Buffer[] = []
|
|
215
|
+
let total = 0
|
|
216
|
+
response.on('data', (chunk: Buffer) => {
|
|
217
|
+
total += chunk.length
|
|
218
|
+
if (total > DOWNLOAD_LIMIT) return finish(null)
|
|
219
|
+
chunks.push(chunk)
|
|
220
|
+
})
|
|
221
|
+
response.on('end', () => finish(Buffer.concat(chunks)))
|
|
222
|
+
response.on('error', () => finish(null))
|
|
223
|
+
},
|
|
224
|
+
)
|
|
225
|
+
request.on('error', () => finish(null))
|
|
226
|
+
// One limit for the whole download, not per step.
|
|
227
|
+
const timer = setTimeout(() => finish(null), DOWNLOAD_MS)
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The `picture` claim of an ID token (already verified by Better Auth when the account was linked). */
|
|
232
|
+
export function pictureFromIdToken(idToken: string | null | undefined): string | null {
|
|
233
|
+
const payload = idToken?.split('.')[1]
|
|
234
|
+
if (!payload) return null
|
|
235
|
+
try {
|
|
236
|
+
const claims = JSON.parse(Buffer.from(payload, 'base64url').toString('utf8')) as { picture?: unknown }
|
|
237
|
+
return typeof claims.picture === 'string' ? claims.picture : null
|
|
238
|
+
} catch {
|
|
239
|
+
return null
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Uses a provider's picture as the avatar of someone who has none (agreed with the owner), centre
|
|
245
|
+
* cropped. Never throws: a picture that cannot be fetched or read is simply not used.
|
|
246
|
+
* `fetchPicture` is for the checks.
|
|
247
|
+
*/
|
|
248
|
+
export async function adoptProviderPicture(userId: string, url: string | null, fetchPicture: (url: string) => Promise<Buffer | null> = download): Promise<boolean> {
|
|
249
|
+
if (!url) return false
|
|
250
|
+
try {
|
|
251
|
+
const { db, t } = await getDatabase()
|
|
252
|
+
const [user] = await db.select({ image: t.users.image }).from(t.users).where(eq(t.users.id, userId)).limit(1)
|
|
253
|
+
if (!user || user.image) return false
|
|
254
|
+
const data = await fetchPicture(url)
|
|
255
|
+
if (!data) return false
|
|
256
|
+
const { width, height } = await readImage(data)
|
|
257
|
+
await store(userId, await render(data, centre(width, height)))
|
|
258
|
+
return true
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (!isValidationError(error)) logError(error, 'could not use the provider picture')
|
|
261
|
+
return false
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// What every fresh copy of the demo holds (PET_ADOPT_DEMO=1, src/lib/demo.ts): the shared demo
|
|
2
|
+
// account, the sample site (the settings, pets, About page and system pages `pnpm seed` adds), the
|
|
3
|
+
// guided setup marked done, and a few pet timeline updates.
|
|
4
|
+
//
|
|
5
|
+
// Only src/db/client.ts calls these: fillDemoSite() on a new, migrated, empty copy (getDatabase()
|
|
6
|
+
// hands the data layer that copy while it runs), and the begin / finish / abandon / drop hooks
|
|
7
|
+
// around it for what lives beside the database (the pictures in memory, Better Auth, the plugin
|
|
8
|
+
// status cache).
|
|
9
|
+
//
|
|
10
|
+
// The fill never calls getAuth(): Better Auth is built on getDatabase(), which waits for this fill,
|
|
11
|
+
// so a fill that waited for Better Auth would wait for itself. The demo account is written directly,
|
|
12
|
+
// with the same password hashing Better Auth checks.
|
|
13
|
+
import { createHash, randomBytes, randomUUID } from 'node:crypto'
|
|
14
|
+
|
|
15
|
+
import { hashPassword } from 'better-auth/crypto'
|
|
16
|
+
import { eq, inArray } from 'drizzle-orm'
|
|
17
|
+
|
|
18
|
+
import { getDatabase } from '@/db/client'
|
|
19
|
+
import { subtractDays, todayISO } from '@/lib/age'
|
|
20
|
+
import { DEMO_ACCOUNT } from '@/lib/demo'
|
|
21
|
+
import { forgetPluginStorageStatus } from '@/plugins/storage'
|
|
22
|
+
|
|
23
|
+
import { forgetAuth } from './auth'
|
|
24
|
+
import { ensurePluginTemplates } from './email-templates'
|
|
25
|
+
import { thumbnailFilename } from './media-url'
|
|
26
|
+
import { ensureSystemPages } from './pages'
|
|
27
|
+
import { addTimelineEntry } from './pet-timeline'
|
|
28
|
+
import { logError } from './result'
|
|
29
|
+
import { addSampleAboutPage, addSamplePets, sampleSiteSettings } from './sample-content'
|
|
30
|
+
import { updateSettings } from './settings'
|
|
31
|
+
import { finishSetup } from './setup'
|
|
32
|
+
import { cancelDemoStorageCopy, emptyDemoStorage, finishDemoStorageCopy, getStorage, startDemoStorageCopy } from './storage'
|
|
33
|
+
|
|
34
|
+
/** A new copy is about to be made: its pictures go into an empty generation of the memory storage. */
|
|
35
|
+
export function beginDemoCopy(): void {
|
|
36
|
+
startDemoStorageCopy()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The new copy is in use. Better Auth was built on the previous copy's database, so it is built
|
|
41
|
+
* again on first use; the plugin status cache is checked again against the new file.
|
|
42
|
+
*/
|
|
43
|
+
export function finishDemoCopy(): void {
|
|
44
|
+
finishDemoStorageCopy()
|
|
45
|
+
forgetAuth()
|
|
46
|
+
forgetPluginStorageStatus()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The new copy failed: the copy still in use keeps its pictures. */
|
|
50
|
+
export function abandonDemoCopy(): void {
|
|
51
|
+
cancelDemoStorageCopy()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The copy was closed (closeDatabase): its pictures go, and nothing built on it is kept. */
|
|
55
|
+
export function dropDemoCopy(): void {
|
|
56
|
+
emptyDemoStorage()
|
|
57
|
+
forgetAuth()
|
|
58
|
+
forgetPluginStorageStatus()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let failFillForChecks = false
|
|
62
|
+
|
|
63
|
+
/** check:demo only: makes the next fills fail after the pets and pictures are written. */
|
|
64
|
+
export function failDemoFillForChecks(on: boolean): void {
|
|
65
|
+
failFillForChecks = on
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Fills a new, empty copy. Throws when a required part fails (the copy is then thrown away). */
|
|
69
|
+
export async function fillDemoSite(): Promise<void> {
|
|
70
|
+
const userId = await addDemoAccount()
|
|
71
|
+
await updateSettings(sampleSiteSettings())
|
|
72
|
+
await finishSetup()
|
|
73
|
+
await ensureSystemPages()
|
|
74
|
+
const pets = await addSamplePets()
|
|
75
|
+
if (pets === 0) throw new Error('The demo copy got no sample pets.')
|
|
76
|
+
await nameSamplePicturesByContent()
|
|
77
|
+
if (failFillForChecks) throw new Error('The demo fill was made to fail (check:demo).')
|
|
78
|
+
if (!(await addSampleAboutPage())) throw new Error('The demo copy got no About page.')
|
|
79
|
+
// Nice to have: the copy works without them.
|
|
80
|
+
try {
|
|
81
|
+
await addSampleTimeline(userId)
|
|
82
|
+
} catch (error) {
|
|
83
|
+
logError(error, 'Could not add the demo pet timeline updates')
|
|
84
|
+
}
|
|
85
|
+
await ensurePluginTemplates()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The shared account every visitor opens the admin as: an admin with a confirmed email and a random
|
|
90
|
+
* password nobody knows (password sign-in is refused in the demo; visitors come in with one click).
|
|
91
|
+
*/
|
|
92
|
+
async function addDemoAccount(): Promise<string> {
|
|
93
|
+
const { t, withTransaction } = await getDatabase()
|
|
94
|
+
const id = randomUUID()
|
|
95
|
+
const password = await hashPassword(randomBytes(32).toString('base64url'))
|
|
96
|
+
const now = new Date()
|
|
97
|
+
await withTransaction(async (tx) => {
|
|
98
|
+
await tx.insert(t.users).values({ id, email: DEMO_ACCOUNT.email, name: DEMO_ACCOUNT.name, emailVerified: true, role: 'admin', createdAt: now, updatedAt: now })
|
|
99
|
+
await tx.insert(t.accounts).values({ id: randomUUID(), accountId: id, providerId: 'credential', userId: id, password, createdAt: now, updatedAt: now })
|
|
100
|
+
})
|
|
101
|
+
return id
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Gives the sample pictures names made from their content, the same on every server instance. A
|
|
106
|
+
* page drawn by one instance links /media/<name>, and the browser's request for the picture may
|
|
107
|
+
* reach another instance, with its own copy: uploads get random names, so it would not have that
|
|
108
|
+
* one. The pictures themselves are the same bytes everywhere (drawn from the same silhouette in the
|
|
109
|
+
* same theme), so naming them by their content (and id, for uniqueness) lets any instance serve
|
|
110
|
+
* them. Only the files and `media.filename` change: pets, pages and timeline updates point at
|
|
111
|
+
* pictures by id.
|
|
112
|
+
*/
|
|
113
|
+
async function nameSamplePicturesByContent(): Promise<void> {
|
|
114
|
+
const { db, t } = await getDatabase()
|
|
115
|
+
const storage = await getStorage()
|
|
116
|
+
for (const row of await db.select({ id: t.media.id, filename: t.media.filename }).from(t.media)) {
|
|
117
|
+
const [file, preview] = await Promise.all([storage.get(row.filename), storage.get(thumbnailFilename(row.filename))])
|
|
118
|
+
if (!file || !preview) throw new Error(`The sample picture ${row.id} is missing from the demo's storage.`)
|
|
119
|
+
const ext = row.filename.slice(row.filename.lastIndexOf('.') + 1)
|
|
120
|
+
const filename = `demo-${row.id}-${createHash('sha256').update(file.body).digest('hex').slice(0, 24)}.${ext}`
|
|
121
|
+
await storage.put(filename, file.body, file.contentType ?? 'application/octet-stream')
|
|
122
|
+
await storage.put(thumbnailFilename(filename), preview.body, preview.contentType ?? 'image/webp')
|
|
123
|
+
await db.update(t.media).set({ filename }).where(eq(t.media.id, row.id))
|
|
124
|
+
await storage.delete(row.filename)
|
|
125
|
+
await storage.delete(thumbnailFilename(row.filename))
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
type SampleUpdate = { daysAgo: number; time?: string; title: string; body: string; photo?: boolean }
|
|
130
|
+
|
|
131
|
+
/** A few dated updates on two sample pets, so the Pet timeline block has something to show. */
|
|
132
|
+
const SAMPLE_TIMELINE: Record<string, SampleUpdate[]> = {
|
|
133
|
+
mochi: [
|
|
134
|
+
{ daysAgo: 42, title: 'Arrived at the rescue', body: 'Found in a car park with her two brothers, hungry but healthy.', photo: true },
|
|
135
|
+
{ daysAgo: 21, time: '10:30', title: 'First vaccinations', body: 'The vet says she is in great shape. Second round in four weeks.' },
|
|
136
|
+
{ daysAgo: 3, time: '16:15', title: 'Ready for her new home', body: 'Mochi is litter-trained and loves her feather wand. Message us to meet her.' },
|
|
137
|
+
],
|
|
138
|
+
biscuit: [
|
|
139
|
+
{ daysAgo: 30, title: 'Moved to a foster home', body: 'Biscuit is staying with a foster family who has two children and a garden.', photo: true },
|
|
140
|
+
{ daysAgo: 7, time: '09:00', title: 'Finished obedience class', body: 'He now sits, stays and walks nicely on the lead.' },
|
|
141
|
+
],
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function addSampleTimeline(userId: string): Promise<void> {
|
|
145
|
+
const { db, t } = await getDatabase()
|
|
146
|
+
const slugs = Object.keys(SAMPLE_TIMELINE)
|
|
147
|
+
const pets = await db.select({ id: t.pets.id, slug: t.pets.slug }).from(t.pets).where(inArray(t.pets.slug, slugs))
|
|
148
|
+
const photos = await db
|
|
149
|
+
.select({ petId: t.petPhotos.petId, mediaId: t.petPhotos.mediaId })
|
|
150
|
+
.from(t.petPhotos)
|
|
151
|
+
.where(inArray(t.petPhotos.petId, pets.map((pet) => pet.id)))
|
|
152
|
+
const today = todayISO()
|
|
153
|
+
for (const pet of pets) {
|
|
154
|
+
const photo = photos.find((row) => row.petId === pet.id)?.mediaId
|
|
155
|
+
for (const update of SAMPLE_TIMELINE[pet.slug] ?? []) {
|
|
156
|
+
await addTimelineEntry(
|
|
157
|
+
pet.id,
|
|
158
|
+
{
|
|
159
|
+
date: subtractDays(today, update.daysAgo),
|
|
160
|
+
time: update.time,
|
|
161
|
+
title: update.title,
|
|
162
|
+
body: update.body,
|
|
163
|
+
photoIds: update.photo && photo ? [photo] : [],
|
|
164
|
+
},
|
|
165
|
+
userId,
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|