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,691 @@
|
|
|
1
|
+
// Email templates: pure code shared by the email builder (client) and the sender (server).
|
|
2
|
+
//
|
|
3
|
+
// A template is Puck data (root + blocks) made only of the blocks below. Agreed with the owner:
|
|
4
|
+
// - Each email the site sends has a purpose; the purpose decides the placeholders ({{name}}) a
|
|
5
|
+
// template may use. Every purpose has a built-in default (DEFAULT_TEMPLATES), so an email never
|
|
6
|
+
// depends on a template existing.
|
|
7
|
+
// - A message to a visitor never contains what the visitor typed (no Details block): anyone can
|
|
8
|
+
// enter any address in a public form, so echoing it would let strangers mail their own text.
|
|
9
|
+
// - Templates are not tied to forms: any plugin sends them (host().sendTemplatedEmail) and fills
|
|
10
|
+
// {{title}} and the Details block with its own content.
|
|
11
|
+
//
|
|
12
|
+
// Every block turns itself into email-safe HTML (tables and inline styles, plus one media query for
|
|
13
|
+
// stacking columns on phones; classic Outlook gets a fixed-width wrapper and bulletproof buttons) and
|
|
14
|
+
// into plain text. The builder's canvas shows that same HTML, so
|
|
15
|
+
// what is designed is what is sent. Stored data is rebuilt by `validateTemplate` from allowed
|
|
16
|
+
// blocks and props only, and everything a person typed is escaped when it is rendered.
|
|
17
|
+
|
|
18
|
+
export const EMAIL_PURPOSES = ['password-reset', 'invite', 'email-verify', 'email-change', 'email-changed', 'account-deletion', 'test', 'team-notification', 'visitor-message'] as const
|
|
19
|
+
export type EmailPurpose = (typeof EMAIL_PURPOSES)[number]
|
|
20
|
+
|
|
21
|
+
/** Placeholders every template can use. */
|
|
22
|
+
export const COMMON_PLACEHOLDERS: Record<string, string> = { siteName: 'The site’s name', siteUrl: 'The site’s address' }
|
|
23
|
+
|
|
24
|
+
export const PURPOSE_INFO: Record<
|
|
25
|
+
EmailPurpose,
|
|
26
|
+
{ label: string; description: string; placeholders: Record<string, string>; required: string[]; details: boolean; sample: Record<string, string> }
|
|
27
|
+
> = {
|
|
28
|
+
'password-reset': {
|
|
29
|
+
label: 'Password reset',
|
|
30
|
+
description: 'Sent when someone asks for a reset link on the sign-in page.',
|
|
31
|
+
placeholders: { name: 'The person’s name', resetLink: 'The one-time reset link (required)', minutes: 'How long the link works, in minutes' },
|
|
32
|
+
required: ['resetLink'],
|
|
33
|
+
details: false,
|
|
34
|
+
sample: { name: 'Alex Rivera', resetLink: 'https://example.com/admin/reset-password?token=sample', minutes: '60' },
|
|
35
|
+
},
|
|
36
|
+
invite: {
|
|
37
|
+
label: 'Invitation',
|
|
38
|
+
description: 'Sent when an admin adds someone with “Email an invite”: they choose their own password.',
|
|
39
|
+
placeholders: {
|
|
40
|
+
name: 'The new person’s name',
|
|
41
|
+
inviteLink: 'The one-time invite link (required)',
|
|
42
|
+
inviterName: 'The admin who invited them',
|
|
43
|
+
role: 'Their role, such as Editor',
|
|
44
|
+
days: 'How long the link works, in days',
|
|
45
|
+
},
|
|
46
|
+
required: ['inviteLink'],
|
|
47
|
+
details: false,
|
|
48
|
+
sample: { name: 'Alex Rivera', inviteLink: 'https://example.com/admin/invite?token=sample', inviterName: 'Sam Lee', role: 'Editor', days: '7' },
|
|
49
|
+
},
|
|
50
|
+
'email-verify': {
|
|
51
|
+
label: 'Confirm your email',
|
|
52
|
+
description: 'Sent when someone asks to confirm their email (the admin shows a banner until they do). Until then they can look around but not change anything.',
|
|
53
|
+
placeholders: { name: 'The person’s name', confirmLink: 'The one-time confirmation link (required)', hours: 'How long the link works, in hours' },
|
|
54
|
+
required: ['confirmLink'],
|
|
55
|
+
details: false,
|
|
56
|
+
sample: { name: 'Alex Rivera', confirmLink: 'https://example.com/admin/confirm-email?token=sample', hours: '24' },
|
|
57
|
+
},
|
|
58
|
+
'email-change': {
|
|
59
|
+
label: 'Confirm new email',
|
|
60
|
+
description: 'Sent to the new address when someone changes their email on the Account page. The change happens when they open its link.',
|
|
61
|
+
placeholders: {
|
|
62
|
+
name: 'The person’s name',
|
|
63
|
+
confirmLink: 'The one-time confirmation link (required)',
|
|
64
|
+
newEmail: 'The new address',
|
|
65
|
+
hours: 'How long the link works, in hours',
|
|
66
|
+
},
|
|
67
|
+
required: ['confirmLink'],
|
|
68
|
+
details: false,
|
|
69
|
+
sample: { name: 'Alex Rivera', confirmLink: 'https://example.com/admin/confirm-email?token=sample', newEmail: 'alex@new.example', hours: '24' },
|
|
70
|
+
},
|
|
71
|
+
'email-changed': {
|
|
72
|
+
label: 'Email change notice',
|
|
73
|
+
description: 'Sent to the old address when someone asks to change their email, and to both addresses when an admin changes it.',
|
|
74
|
+
placeholders: { name: 'The person’s name', oldEmail: 'The old address', newEmail: 'The new address', changedBy: 'Who asked for it: “you” or the admin’s name' },
|
|
75
|
+
required: [],
|
|
76
|
+
details: false,
|
|
77
|
+
sample: { name: 'Alex Rivera', oldEmail: 'alex@old.example', newEmail: 'alex@new.example', changedBy: 'you' },
|
|
78
|
+
},
|
|
79
|
+
'account-deletion': {
|
|
80
|
+
label: 'Account deletion',
|
|
81
|
+
description: 'Sent when someone asks to delete their own account: it is closed at once and deleted after 30 days.',
|
|
82
|
+
placeholders: { name: 'The person’s name', date: 'The day it will be deleted', days: 'How many days until then' },
|
|
83
|
+
required: [],
|
|
84
|
+
details: false,
|
|
85
|
+
sample: { name: 'Alex Rivera', date: '26 December 2026', days: '30' },
|
|
86
|
+
},
|
|
87
|
+
test: {
|
|
88
|
+
label: 'Test email',
|
|
89
|
+
description: 'Sent by “Send a test email” in Email > Sending.',
|
|
90
|
+
placeholders: { senderName: 'Who sent the test' },
|
|
91
|
+
required: [],
|
|
92
|
+
details: false,
|
|
93
|
+
sample: { senderName: 'Alex Rivera' },
|
|
94
|
+
},
|
|
95
|
+
'team-notification': {
|
|
96
|
+
label: 'Team notification',
|
|
97
|
+
description: 'Sent to your team when something comes in, such as a form response. Can list the details.',
|
|
98
|
+
placeholders: { title: 'What it is about, such as the form’s name' },
|
|
99
|
+
required: [],
|
|
100
|
+
details: true,
|
|
101
|
+
sample: { title: 'Adoption enquiry' },
|
|
102
|
+
},
|
|
103
|
+
'visitor-message': {
|
|
104
|
+
label: 'Message to a visitor',
|
|
105
|
+
description: 'Sent to someone outside the team, such as a confirmation after they fill in a form. Never repeats what they typed.',
|
|
106
|
+
placeholders: { title: 'What it is about, such as the form’s name' },
|
|
107
|
+
required: [],
|
|
108
|
+
details: false,
|
|
109
|
+
sample: { title: 'Adoption enquiry' },
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const isEmailPurpose = (value: unknown): value is EmailPurpose => (EMAIL_PURPOSES as readonly unknown[]).includes(value)
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The site's own emails (agreed with the owner): no library of templates. The built-in template is
|
|
117
|
+
* edited in place, and "Restore default" brings it back. Form emails keep a library instead,
|
|
118
|
+
* so each form can pick its own.
|
|
119
|
+
*/
|
|
120
|
+
export const SYSTEM_PURPOSES = ['password-reset', 'invite', 'email-verify', 'email-change', 'email-changed', 'account-deletion', 'test'] as const satisfies readonly EmailPurpose[]
|
|
121
|
+
export type SystemPurpose = (typeof SYSTEM_PURPOSES)[number]
|
|
122
|
+
export const isSystemPurpose = (value: unknown): value is SystemPurpose => (SYSTEM_PURPOSES as readonly unknown[]).includes(value)
|
|
123
|
+
export const LIBRARY_PURPOSES = EMAIL_PURPOSES.filter((purpose) => !isSystemPurpose(purpose))
|
|
124
|
+
|
|
125
|
+
/** The placeholders a purpose may use (its own plus the common ones). */
|
|
126
|
+
export function placeholdersFor(purpose: EmailPurpose): Record<string, string> {
|
|
127
|
+
return { ...COMMON_PLACEHOLDERS, ...PURPOSE_INFO[purpose].placeholders }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- Template data ------------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
export type Align = 'left' | 'center' | 'right'
|
|
133
|
+
export type EmailImage = { id: number; url: string; alt: string }
|
|
134
|
+
export type BlockData =
|
|
135
|
+
| { type: 'Heading'; props: { id: string; text: string; level: 'h1' | 'h2'; align: Align } }
|
|
136
|
+
| { type: 'Text'; props: { id: string; text: string; align: Align; size: 'normal' | 'small' } }
|
|
137
|
+
| { type: 'Button'; props: { id: string; label: string; url: string; align: Align; style: 'solid' | 'outline' } }
|
|
138
|
+
| { type: 'Image'; props: { id: string; image: EmailImage | null; alt: string; width: 'full' | 'half'; align: Align; link: string } }
|
|
139
|
+
| { type: 'Divider'; props: { id: string } }
|
|
140
|
+
| { type: 'Spacer'; props: { id: string; size: 'small' | 'medium' | 'large' } }
|
|
141
|
+
| { type: 'Columns'; props: { id: string; left: BlockData[]; right: BlockData[] } }
|
|
142
|
+
| { type: 'Details'; props: { id: string; title: string } }
|
|
143
|
+
|
|
144
|
+
/** Where the site's name goes next to the logo (the email's logo): beside it or under it, either way round. */
|
|
145
|
+
export const LOGO_LAYOUTS = ['horizontal', 'horizontal-reverse', 'vertical', 'vertical-reverse'] as const
|
|
146
|
+
export type LogoLayout = (typeof LOGO_LAYOUTS)[number]
|
|
147
|
+
|
|
148
|
+
export type LogoSize = 'small' | 'medium' | 'large'
|
|
149
|
+
/**
|
|
150
|
+
* The email's settings. The logo at the top is the site's logo from Site settings (or its name,
|
|
151
|
+
* without one): size, alignment, a link to the site, and the site's name beside or under it.
|
|
152
|
+
*/
|
|
153
|
+
export type TemplateRoot = {
|
|
154
|
+
subject: string
|
|
155
|
+
preheader: string
|
|
156
|
+
showLogo: boolean
|
|
157
|
+
logoSize: LogoSize
|
|
158
|
+
logoAlign: Align
|
|
159
|
+
logoLink: boolean
|
|
160
|
+
showSiteName: boolean
|
|
161
|
+
logoLayout: LogoLayout
|
|
162
|
+
footer: string
|
|
163
|
+
}
|
|
164
|
+
export type TemplateData = { root: { props: TemplateRoot }; content: BlockData[] }
|
|
165
|
+
|
|
166
|
+
export const TEMPLATE_LIMITS = { blocks: 60, text: 5000, heading: 200, label: 80, subject: 200, preheader: 200, footer: 1000, url: 2000, name: 80 }
|
|
167
|
+
|
|
168
|
+
const ALIGNS: readonly Align[] = ['left', 'center', 'right']
|
|
169
|
+
const PLACEHOLDER = /\{\{\s*([A-Za-z]+)\s*\}\}/g
|
|
170
|
+
const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g
|
|
171
|
+
|
|
172
|
+
// --- Validation (rebuilds the data from allowed parts) -----------------------------------------
|
|
173
|
+
|
|
174
|
+
export type TemplateCheck = { ok: true; data: TemplateData } | { ok: false; errors: string[] }
|
|
175
|
+
|
|
176
|
+
const str = (value: unknown, max: number): string | null => {
|
|
177
|
+
if (value === undefined || value === null) return ''
|
|
178
|
+
if (typeof value !== 'string') return null
|
|
179
|
+
const clean = value.replace(CONTROL, '').replace(/\r\n?/g, '\n')
|
|
180
|
+
return clean.length > max ? null : clean
|
|
181
|
+
}
|
|
182
|
+
const oneOf = <T extends string>(value: unknown, options: readonly T[], fallback: T): T => (options.includes(value as T) ? (value as T) : fallback)
|
|
183
|
+
|
|
184
|
+
/** One-time links an email may carry as a whole button or image link, when its purpose has them. */
|
|
185
|
+
export const LINK_PLACEHOLDERS = ['resetLink', 'inviteLink', 'confirmLink'] as const
|
|
186
|
+
|
|
187
|
+
/** The one-time link placeholders a purpose has ({{resetLink}}, {{inviteLink}}). */
|
|
188
|
+
export function linkPlaceholdersFor(purpose: EmailPurpose): string[] {
|
|
189
|
+
const own = placeholdersFor(purpose)
|
|
190
|
+
return LINK_PLACEHOLDERS.filter((name) => name in own)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** A link a button or image may open: {{resetLink}} or {{inviteLink}}, {{siteUrl}} (with a path), a site path, or http(s). */
|
|
194
|
+
export function isAllowedEmailUrl(url: string, purpose: EmailPurpose): boolean {
|
|
195
|
+
const trimmed = url.trim()
|
|
196
|
+
if (!trimmed) return false
|
|
197
|
+
const only = /^\{\{\s*([A-Za-z]+)\s*\}\}(\/[^\s"'<>\\]*)?$/.exec(trimmed)
|
|
198
|
+
if (only) {
|
|
199
|
+
if (only[1] === 'siteUrl') return true
|
|
200
|
+
return linkPlaceholdersFor(purpose).includes(only[1]) && only[2] === undefined
|
|
201
|
+
}
|
|
202
|
+
if (/\{\{/.test(trimmed)) return false
|
|
203
|
+
if (/^\/(?!\/)[^\s"'<>\\]*$/.test(trimmed)) return true
|
|
204
|
+
try {
|
|
205
|
+
const parsed = new URL(trimmed)
|
|
206
|
+
return (parsed.protocol === 'https:' || parsed.protocol === 'http:') && !parsed.username && !parsed.password
|
|
207
|
+
} catch {
|
|
208
|
+
return false
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const placeholdersIn = (text: string) => [...text.matchAll(PLACEHOLDER)].map((match) => match[1])
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Checks a template for a purpose and returns a clean copy built from the allowed blocks and props.
|
|
216
|
+
* Unknown blocks, nested columns, a Details block where details are not allowed, unknown
|
|
217
|
+
* placeholders, bad links and a missing required placeholder are errors.
|
|
218
|
+
*/
|
|
219
|
+
export function validateTemplate(raw: unknown, purpose: EmailPurpose): TemplateCheck {
|
|
220
|
+
const errors: string[] = []
|
|
221
|
+
const allowed = placeholdersFor(purpose)
|
|
222
|
+
const used = new Set<string>()
|
|
223
|
+
const data = raw && typeof raw === 'object' ? (raw as { root?: { props?: Record<string, unknown> }; content?: unknown }) : {}
|
|
224
|
+
const rootProps = data.root?.props ?? {}
|
|
225
|
+
let count = 0
|
|
226
|
+
|
|
227
|
+
const checkText = (where: string, value: unknown, max: number): string => {
|
|
228
|
+
const text = str(value, max)
|
|
229
|
+
if (text === null) {
|
|
230
|
+
errors.push(`${where}: use at most ${max} characters.`)
|
|
231
|
+
return ''
|
|
232
|
+
}
|
|
233
|
+
for (const name of placeholdersIn(text)) {
|
|
234
|
+
if (name in allowed) used.add(name)
|
|
235
|
+
else errors.push(`${where}: {{${name}}} is not available in this kind of email.`)
|
|
236
|
+
}
|
|
237
|
+
return text
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const blocks = (list: unknown, where: string, nested: boolean): BlockData[] => {
|
|
241
|
+
if (list === undefined || list === null) return []
|
|
242
|
+
if (!Array.isArray(list)) {
|
|
243
|
+
errors.push(`${where}: not a list of blocks.`)
|
|
244
|
+
return []
|
|
245
|
+
}
|
|
246
|
+
const out: BlockData[] = []
|
|
247
|
+
for (const [index, item] of list.entries()) {
|
|
248
|
+
count++
|
|
249
|
+
if (count > TEMPLATE_LIMITS.blocks) {
|
|
250
|
+
errors.push(`Use at most ${TEMPLATE_LIMITS.blocks} blocks.`)
|
|
251
|
+
return out
|
|
252
|
+
}
|
|
253
|
+
const block = item && typeof item === 'object' ? (item as { type?: unknown; props?: Record<string, unknown> }) : {}
|
|
254
|
+
const props = block.props ?? {}
|
|
255
|
+
const id = typeof props.id === 'string' && /^[\w-]{1,80}$/.test(props.id) ? props.id : `block-${count}`
|
|
256
|
+
const at = `${where} block ${index + 1}${typeof block.type === 'string' ? ` (${block.type})` : ''}`
|
|
257
|
+
switch (block.type) {
|
|
258
|
+
case 'Heading':
|
|
259
|
+
out.push({
|
|
260
|
+
type: 'Heading',
|
|
261
|
+
props: { id, text: checkText(at, props.text, TEMPLATE_LIMITS.heading), level: oneOf(props.level, ['h1', 'h2'] as const, 'h2'), align: oneOf(props.align, ALIGNS, 'left') },
|
|
262
|
+
})
|
|
263
|
+
break
|
|
264
|
+
case 'Text':
|
|
265
|
+
out.push({
|
|
266
|
+
type: 'Text',
|
|
267
|
+
props: { id, text: checkText(at, props.text, TEMPLATE_LIMITS.text), align: oneOf(props.align, ALIGNS, 'left'), size: oneOf(props.size, ['normal', 'small'] as const, 'normal') },
|
|
268
|
+
})
|
|
269
|
+
break
|
|
270
|
+
case 'Button': {
|
|
271
|
+
const label = checkText(at, props.label, TEMPLATE_LIMITS.label)
|
|
272
|
+
const url = (str(props.url, TEMPLATE_LIMITS.url) ?? '').trim()
|
|
273
|
+
if (!label.trim()) errors.push(`${at}: add the button’s text.`)
|
|
274
|
+
if (!url) errors.push(`${at}: add the link the button opens.`)
|
|
275
|
+
else if (!isAllowedEmailUrl(url, purpose)) errors.push(`${at}: the link must be a web address (https://…), a path on this site (/…), {{siteUrl}}${linkPlaceholdersFor(purpose).map((name) => ` or {{${name}}}`).join('')}.`)
|
|
276
|
+
else for (const name of placeholdersIn(url)) used.add(name)
|
|
277
|
+
out.push({ type: 'Button', props: { id, label, url, align: oneOf(props.align, ALIGNS, 'left'), style: oneOf(props.style, ['solid', 'outline'] as const, 'solid') } })
|
|
278
|
+
break
|
|
279
|
+
}
|
|
280
|
+
case 'Image': {
|
|
281
|
+
const image = props.image && typeof props.image === 'object' ? (props.image as { id?: unknown; url?: unknown; alt?: unknown }) : null
|
|
282
|
+
const imageId = Number(image?.id)
|
|
283
|
+
const imageUrl = typeof image?.url === 'string' ? image.url : ''
|
|
284
|
+
const clean: EmailImage | null =
|
|
285
|
+
image && Number.isSafeInteger(imageId) && imageId > 0 && /^\/media\/[\w.-]{1,200}$/.test(imageUrl)
|
|
286
|
+
? { id: imageId, url: imageUrl, alt: (str(image.alt, 300) ?? '').trim() }
|
|
287
|
+
: null
|
|
288
|
+
if (image && !clean) errors.push(`${at}: choose the image from the media library.`)
|
|
289
|
+
const link = (str(props.link, TEMPLATE_LIMITS.url) ?? '').trim()
|
|
290
|
+
if (link && !isAllowedEmailUrl(link, purpose)) errors.push(`${at}: the image link must be a web address, a path on this site or {{siteUrl}}.`)
|
|
291
|
+
out.push({
|
|
292
|
+
type: 'Image',
|
|
293
|
+
props: { id, image: clean, alt: checkText(at, props.alt, 300), width: oneOf(props.width, ['full', 'half'] as const, 'full'), align: oneOf(props.align, ALIGNS, 'center'), link },
|
|
294
|
+
})
|
|
295
|
+
break
|
|
296
|
+
}
|
|
297
|
+
case 'Divider':
|
|
298
|
+
out.push({ type: 'Divider', props: { id } })
|
|
299
|
+
break
|
|
300
|
+
case 'Spacer':
|
|
301
|
+
out.push({ type: 'Spacer', props: { id, size: oneOf(props.size, ['small', 'medium', 'large'] as const, 'medium') } })
|
|
302
|
+
break
|
|
303
|
+
case 'Columns':
|
|
304
|
+
if (nested) {
|
|
305
|
+
errors.push(`${at}: columns cannot go inside columns.`)
|
|
306
|
+
break
|
|
307
|
+
}
|
|
308
|
+
out.push({ type: 'Columns', props: { id, left: blocks(props.left, `${at}, left column,`, true), right: blocks(props.right, `${at}, right column,`, true) } })
|
|
309
|
+
break
|
|
310
|
+
case 'Details':
|
|
311
|
+
if (!PURPOSE_INFO[purpose].details) {
|
|
312
|
+
errors.push(`${at}: the details can only go in “${PURPOSE_INFO['team-notification'].label}” emails.`)
|
|
313
|
+
break
|
|
314
|
+
}
|
|
315
|
+
out.push({ type: 'Details', props: { id, title: checkText(at, props.title, TEMPLATE_LIMITS.heading) } })
|
|
316
|
+
break
|
|
317
|
+
default:
|
|
318
|
+
errors.push(`${at}: this kind of block cannot be used in an email.`)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return out
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const content = blocks(data.content, 'The email’s', false)
|
|
325
|
+
const subject = checkText('Subject', rootProps.subject, TEMPLATE_LIMITS.subject).replace(/\s+/g, ' ').trim()
|
|
326
|
+
if (!subject) errors.push('Subject: add a subject line.')
|
|
327
|
+
const root: TemplateRoot = {
|
|
328
|
+
subject,
|
|
329
|
+
preheader: checkText('Preview text', rootProps.preheader, TEMPLATE_LIMITS.preheader).replace(/\s+/g, ' ').trim(),
|
|
330
|
+
showLogo: rootProps.showLogo !== false,
|
|
331
|
+
// Missing values keep the look templates had before these options: medium, centred, no link, no name.
|
|
332
|
+
logoSize: oneOf(rootProps.logoSize, ['small', 'medium', 'large'] as const, 'medium'),
|
|
333
|
+
logoAlign: oneOf(rootProps.logoAlign, ALIGNS, 'center'),
|
|
334
|
+
logoLink: rootProps.logoLink === true,
|
|
335
|
+
showSiteName: rootProps.showSiteName === true,
|
|
336
|
+
logoLayout: oneOf(rootProps.logoLayout, LOGO_LAYOUTS, 'horizontal'),
|
|
337
|
+
footer: checkText('Footer', rootProps.footer, TEMPLATE_LIMITS.footer),
|
|
338
|
+
}
|
|
339
|
+
if (!content.length) errors.push('Add at least one block.')
|
|
340
|
+
for (const name of PURPOSE_INFO[purpose].required) {
|
|
341
|
+
if (!used.has(name)) errors.push(`This email must include {{${name}}}, for example as a button’s link.`)
|
|
342
|
+
}
|
|
343
|
+
return errors.length ? { ok: false, errors: [...new Set(errors)] } : { ok: true, data: { root: { props: root }, content } }
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// --- Rendering ----------------------------------------------------------------------------------
|
|
347
|
+
|
|
348
|
+
export type EmailTheme = { primary: string; onPrimary: string; ink: string; muted: string; background: string; surface: string; line: string; font: string; headingFont: string; radius: number }
|
|
349
|
+
|
|
350
|
+
export type RenderContext = {
|
|
351
|
+
/** Placeholder values. Missing ones render as nothing (the builder shows them as {{name}} instead). */
|
|
352
|
+
values: Record<string, string>
|
|
353
|
+
/** For the Details block (team notifications only): label and value pairs, such as a form's answers. */
|
|
354
|
+
details?: Array<{ label: string; value: string }>
|
|
355
|
+
theme: EmailTheme
|
|
356
|
+
/** The site's address (no trailing slash): makes /media/… and /paths absolute. */
|
|
357
|
+
origin: string
|
|
358
|
+
logo: { url: string; alt: string } | null
|
|
359
|
+
/** In the builder: show placeholders as {{name}} chips instead of values. */
|
|
360
|
+
showPlaceholders?: boolean
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* An image's address in an email: absolute, and a WebP upload as its PNG copy (/media/email/…),
|
|
365
|
+
* because classic Outlook and some older clients cannot show WebP. The builder's canvas (a browser)
|
|
366
|
+
* keeps the original.
|
|
367
|
+
*/
|
|
368
|
+
export function emailImageSrc(url: string, ctx: RenderContext): string {
|
|
369
|
+
const webp = /^\/media\/([a-z0-9][a-z0-9-]*)\.webp$/.exec(url)
|
|
370
|
+
const path = webp && !ctx.showPlaceholders ? `/media/email/${webp[1]}.png` : url
|
|
371
|
+
return path.startsWith('/') ? `${ctx.origin}${path}` : path
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export const escapeHtml = (value: string) =>
|
|
375
|
+
value.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c] as string)
|
|
376
|
+
|
|
377
|
+
const safeColor = (value: string, fallback: string) => (/^#[0-9a-f]{3,8}$/i.test(value) ? value : fallback)
|
|
378
|
+
const safeFont = (value: string) => value.replace(/[^\w\s,'-]/g, '')
|
|
379
|
+
|
|
380
|
+
/** Text with placeholders filled, as escaped HTML. */
|
|
381
|
+
function fill(text: string, ctx: RenderContext): string {
|
|
382
|
+
let out = ''
|
|
383
|
+
let last = 0
|
|
384
|
+
for (const match of text.matchAll(PLACEHOLDER)) {
|
|
385
|
+
out += escapeHtml(text.slice(last, match.index))
|
|
386
|
+
const name = match[1]
|
|
387
|
+
out += ctx.showPlaceholders
|
|
388
|
+
? `<span style="background:#eef2ff;color:#3730a3;border-radius:4px;padding:0 3px;font-family:monospace;font-size:0.9em">{{${escapeHtml(name)}}}</span>`
|
|
389
|
+
: escapeHtml(ctx.values[name] ?? '')
|
|
390
|
+
last = (match.index ?? 0) + match[0].length
|
|
391
|
+
}
|
|
392
|
+
return out + escapeHtml(text.slice(last))
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Text with placeholders filled, as plain text. */
|
|
396
|
+
function fillText(text: string, ctx: RenderContext): string {
|
|
397
|
+
return text.replace(PLACEHOLDER, (_, name: string) => (ctx.showPlaceholders ? `{{${name}}}` : (ctx.values[name] ?? '')))
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** A link with placeholders filled and site paths made absolute. Never anything but http(s). */
|
|
401
|
+
function fillUrl(url: string, ctx: RenderContext): string {
|
|
402
|
+
const filled = fillText(url, { ...ctx, showPlaceholders: false }).trim()
|
|
403
|
+
const absolute = filled.startsWith('/') && !filled.startsWith('//') ? `${ctx.origin}${filled}` : filled
|
|
404
|
+
return /^https?:\/\//i.test(absolute) ? absolute : '#'
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const paragraphs = (html: string) =>
|
|
408
|
+
html
|
|
409
|
+
.split(/\n{2,}/)
|
|
410
|
+
.map((part) => part.trim().replace(/\n/g, '<br>'))
|
|
411
|
+
.filter(Boolean)
|
|
412
|
+
|
|
413
|
+
const SPACER = { small: 12, medium: 24, large: 40 }
|
|
414
|
+
|
|
415
|
+
/** One block as email HTML (inside the content cell). */
|
|
416
|
+
export function blockHtml(block: BlockData, ctx: RenderContext): string {
|
|
417
|
+
const t = ctx.theme
|
|
418
|
+
const font = `font-family:${safeFont(t.font)};`
|
|
419
|
+
switch (block.type) {
|
|
420
|
+
case 'Heading': {
|
|
421
|
+
const size = block.props.level === 'h1' ? 26 : 20
|
|
422
|
+
return `<${block.props.level} style="margin:0 0 16px;font-family:${safeFont(t.headingFont)};font-size:${size}px;line-height:1.3;font-weight:700;color:${t.ink};text-align:${block.props.align}">${fill(block.props.text, ctx)}</${block.props.level}>`
|
|
423
|
+
}
|
|
424
|
+
case 'Text': {
|
|
425
|
+
const size = block.props.size === 'small' ? 13 : 16
|
|
426
|
+
const color = block.props.size === 'small' ? t.muted : t.ink
|
|
427
|
+
return paragraphs(fill(block.props.text, ctx))
|
|
428
|
+
.map((part) => `<p style="margin:0 0 16px;${font}font-size:${size}px;line-height:1.6;color:${color};text-align:${block.props.align}">${part}</p>`)
|
|
429
|
+
.join('')
|
|
430
|
+
}
|
|
431
|
+
case 'Button': {
|
|
432
|
+
// A "bulletproof" button: the colour and padding sit on a table cell, which every client draws;
|
|
433
|
+
// classic Outlook (Word's engine) ignores padding on links, so it gets `mso-padding-alt` and
|
|
434
|
+
// `bgcolor` on the cell. Other clients use the link's own padding, so all of it is clickable.
|
|
435
|
+
const solid = block.props.style === 'solid'
|
|
436
|
+
const href = ctx.showPlaceholders ? '#' : escapeHtml(fillUrl(block.props.url, ctx))
|
|
437
|
+
const color = solid ? t.onPrimary : t.primary
|
|
438
|
+
const cellColor = solid ? ` bgcolor="${t.primary}"` : ''
|
|
439
|
+
const tableAlign = block.props.align === 'center' ? 'center' : block.props.align
|
|
440
|
+
return `<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="${tableAlign}" style="margin:0 0 16px${block.props.align === 'center' ? ';margin-left:auto;margin-right:auto' : ''}"><tr><td align="center"${cellColor} style="border-radius:${t.radius}px;background:${solid ? t.primary : 'transparent'};border:2px solid ${t.primary};mso-padding-alt:12px 22px"><a href="${href}" target="_blank" style="display:inline-block;padding:12px 22px;${font}font-size:16px;font-weight:700;line-height:1.2;color:${color};text-decoration:none;border-radius:${t.radius}px">${fill(block.props.label, ctx)}</a></td></tr></table><div style="clear:both;height:0;line-height:0;font-size:0"> </div>`
|
|
441
|
+
}
|
|
442
|
+
case 'Image': {
|
|
443
|
+
const image = block.props.image
|
|
444
|
+
if (!image) return ctx.showPlaceholders ? `<p style="margin:0 0 16px;${font}color:${t.muted};text-align:center;border:1px dashed ${t.line};padding:24px">Choose an image</p>` : ''
|
|
445
|
+
const width = block.props.width === 'half' ? 268 : 536
|
|
446
|
+
const alt = fill(block.props.alt || image.alt, { ...ctx, showPlaceholders: false })
|
|
447
|
+
const img = `<img src="${escapeHtml(emailImageSrc(image.url, ctx))}" width="${width}" alt="${alt}" style="display:inline-block;width:100%;max-width:${width}px;height:auto;border:0;text-decoration:none;border-radius:${t.radius}px">`
|
|
448
|
+
const linked = block.props.link && !ctx.showPlaceholders ? `<a href="${escapeHtml(fillUrl(block.props.link, ctx))}" target="_blank">${img}</a>` : img
|
|
449
|
+
return `<div style="margin:0 0 16px;text-align:${block.props.align}">${linked}</div>`
|
|
450
|
+
}
|
|
451
|
+
case 'Divider':
|
|
452
|
+
return `<div style="margin:8px 0 24px;border-top:1px solid ${t.line};line-height:0;font-size:0"> </div>`
|
|
453
|
+
case 'Spacer':
|
|
454
|
+
return `<div style="height:${SPACER[block.props.size]}px;line-height:${SPACER[block.props.size]}px;font-size:0"> </div>`
|
|
455
|
+
case 'Columns':
|
|
456
|
+
return columnsHtml(block.props.left.map((child) => blockHtml(child, ctx)).join(''), block.props.right.map((child) => blockHtml(child, ctx)).join(''))
|
|
457
|
+
case 'Details': {
|
|
458
|
+
const details =
|
|
459
|
+
ctx.details ??
|
|
460
|
+
(ctx.showPlaceholders
|
|
461
|
+
? [
|
|
462
|
+
{ label: 'Your name', value: 'Sample answer' },
|
|
463
|
+
{ label: 'Message', value: 'Each detail, such as a form’s answers, appears here.' },
|
|
464
|
+
]
|
|
465
|
+
: [])
|
|
466
|
+
const title = block.props.title ? `<p style="margin:0 0 8px;${font}font-size:16px;font-weight:700;color:${t.ink}">${fill(block.props.title, ctx)}</p>` : ''
|
|
467
|
+
const rows = details
|
|
468
|
+
.map(
|
|
469
|
+
(detail) =>
|
|
470
|
+
`<tr><td valign="top" style="padding:8px 12px 8px 0;border-top:1px solid ${t.line};${font}font-size:14px;font-weight:700;color:${t.ink};width:35%">${escapeHtml(detail.label)}</td><td valign="top" style="padding:8px 0;border-top:1px solid ${t.line};${font}font-size:14px;color:${t.ink}">${escapeHtml(detail.value || '(blank)').replace(/\n/g, '<br>')}</td></tr>`,
|
|
471
|
+
)
|
|
472
|
+
.join('')
|
|
473
|
+
return `${title}<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:0 0 16px">${rows}</table>`
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Two columns (stacked on phones by the layout's media query). Both cells are already HTML. */
|
|
479
|
+
export function columnsHtml(left: string, right: string): string {
|
|
480
|
+
return `<table role="presentation" class="pa-columns" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:0 0 8px"><tr><td class="pa-column" width="50%" valign="top" style="padding-right:12px">${left}</td><td class="pa-column" width="50%" valign="top" style="padding-left:12px">${right}</td></tr></table>`
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** One block as plain text. */
|
|
484
|
+
export function blockText(block: BlockData, ctx: RenderContext): string {
|
|
485
|
+
switch (block.type) {
|
|
486
|
+
case 'Heading':
|
|
487
|
+
return fillText(block.props.text, ctx).toUpperCase()
|
|
488
|
+
case 'Text':
|
|
489
|
+
return fillText(block.props.text, ctx).trim()
|
|
490
|
+
case 'Button':
|
|
491
|
+
return `${fillText(block.props.label, ctx)}: ${fillUrl(block.props.url, ctx)}`
|
|
492
|
+
case 'Image':
|
|
493
|
+
return block.props.image && block.props.alt ? `[${fillText(block.props.alt, ctx)}]` : ''
|
|
494
|
+
case 'Divider':
|
|
495
|
+
return '----'
|
|
496
|
+
case 'Spacer':
|
|
497
|
+
return ''
|
|
498
|
+
case 'Columns':
|
|
499
|
+
return [...block.props.left, ...block.props.right]
|
|
500
|
+
.map((child) => blockText(child, ctx))
|
|
501
|
+
.filter(Boolean)
|
|
502
|
+
.join('\n\n')
|
|
503
|
+
case 'Details': {
|
|
504
|
+
const lines = (ctx.details ?? []).map((detail) => `${detail.label}: ${detail.value || '(blank)'}`)
|
|
505
|
+
return [block.props.title ? fillText(block.props.title, ctx) : '', ...lines].filter(Boolean).join('\n')
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** The logo row's HTML (or the site's name), shared by the email and the builder's canvas. */
|
|
511
|
+
export function logoHtml(root: TemplateRoot, ctx: RenderContext): string {
|
|
512
|
+
if (!root.showLogo) return ''
|
|
513
|
+
const { logoSize, logoAlign: align, logoLink, showSiteName, logoLayout: layout } = root
|
|
514
|
+
const height = LOGO_HEIGHT[logoSize]
|
|
515
|
+
const link = (html: string) => (logoLink && !ctx.showPlaceholders ? `<a href="${escapeHtml(ctx.origin)}" target="_blank" style="text-decoration:none">${html}</a>` : html)
|
|
516
|
+
// Without a logo, or without the name: one mark. Otherwise a small table (classic Outlook keeps it).
|
|
517
|
+
if (!ctx.logo || !showSiteName) return link(brandHtml(ctx, height))
|
|
518
|
+
const logo = link(logoImgHtml(ctx.logo, ctx, height))
|
|
519
|
+
const name = link(siteNameHtml(ctx, height))
|
|
520
|
+
const [first, second] = layout.endsWith('reverse') ? [name, logo] : [logo, name]
|
|
521
|
+
const center = align === 'center' ? ';margin-left:auto;margin-right:auto' : ''
|
|
522
|
+
const rows = layout.startsWith('horizontal')
|
|
523
|
+
? `<tr><td valign="middle" style="padding-right:12px">${first}</td><td valign="middle">${second}</td></tr>`
|
|
524
|
+
: `<tr><td align="${align}" style="padding-bottom:8px">${first}</td></tr><tr><td align="${align}">${second}</td></tr>`
|
|
525
|
+
return `<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="${align}" style="margin:0${center}">${rows}</table>`
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** Logo heights (px) for the email's logo: small, medium (the default), large. */
|
|
529
|
+
const LOGO_HEIGHT = { small: 32, medium: 48, large: 64 } as const
|
|
530
|
+
|
|
531
|
+
/** The site's logo at `height` px, or its name in the heading font when it has no logo. */
|
|
532
|
+
function brandHtml(ctx: RenderContext, height: number): string {
|
|
533
|
+
return ctx.logo ? logoImgHtml(ctx.logo, ctx, height) : siteNameHtml(ctx, height)
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function logoImgHtml(logo: NonNullable<RenderContext['logo']>, ctx: RenderContext, height: number): string {
|
|
537
|
+
return `<img src="${escapeHtml(emailImageSrc(logo.url, ctx))}" alt="${escapeHtml(logo.alt || ctx.values.siteName || '')}" height="${height}" style="display:inline-block;height:${height}px;width:auto;border:0;vertical-align:middle">`
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** The site's name in the heading font, sized to sit with a logo `height` px tall. */
|
|
541
|
+
function siteNameHtml(ctx: RenderContext, height: number): string {
|
|
542
|
+
const t = ctx.theme
|
|
543
|
+
return `<span style="font-family:${safeFont(t.headingFont)};font-size:${Math.round(height * 0.42)}px;line-height:1.2;font-weight:700;color:${t.ink}">${escapeHtml(ctx.values.siteName ?? '')}</span>`
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** The footer's HTML, shared by the email and the builder's canvas. */
|
|
547
|
+
export function footerHtml(root: TemplateRoot, ctx: RenderContext): string {
|
|
548
|
+
const t = ctx.theme
|
|
549
|
+
return paragraphs(fill(root.footer, ctx))
|
|
550
|
+
.map((part) => `<p style="margin:0 0 8px;font-family:${safeFont(t.font)};font-size:12px;line-height:1.5;color:${t.muted};text-align:center">${part}</p>`)
|
|
551
|
+
.join('')
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** The whole email around the blocks: background, a 600 px card, the logo and the footer. */
|
|
555
|
+
export function layoutHtml(inner: string, root: TemplateRoot, ctx: RenderContext, subject: string): string {
|
|
556
|
+
const t = ctx.theme
|
|
557
|
+
const logo = logoHtml(root, ctx)
|
|
558
|
+
const footer = footerHtml(root, ctx)
|
|
559
|
+
// The preview text most inboxes show after the subject; hidden in the email itself.
|
|
560
|
+
const preheader = root.preheader ? `<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:transparent;mso-hide:all">${fill(root.preheader, { ...ctx, showPlaceholders: false })}</div>` : ''
|
|
561
|
+
// Classic Outlook (Word's engine): the conditional comments give it a fixed 600 px table (it ignores
|
|
562
|
+
// max-width) and 96 DPI, so images are not rescaled; `bgcolor` attributes for its backgrounds.
|
|
563
|
+
return `<!doctype html>
|
|
564
|
+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="color-scheme" content="light"><meta name="x-apple-disable-message-reformatting"><title>${escapeHtml(subject)}</title>
|
|
565
|
+
<!--[if mso]><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]-->
|
|
566
|
+
<style>@media (max-width: 600px) { .pa-columns .pa-column { display: block !important; width: 100% !important; padding: 0 !important; } }</style></head>
|
|
567
|
+
<body bgcolor="${t.background}" style="margin:0;padding:0;background:${t.background}">${preheader}
|
|
568
|
+
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="${t.background}" style="background:${t.background}"><tr><td align="center" style="padding:24px 12px">
|
|
569
|
+
<!--[if mso]><table role="presentation" width="600" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]-->
|
|
570
|
+
<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" bgcolor="${t.surface}" style="width:100%;max-width:600px;background:${t.surface};border-radius:${t.radius}px;border:1px solid ${t.line}">
|
|
571
|
+
${logo ? `<tr><td align="${root.logoAlign}" style="padding:28px 32px 0">${logo}</td></tr>` : ''}<tr><td style="padding:28px 32px 12px;font-family:${safeFont(t.font)};color:${t.ink}">${inner}</td></tr>${footer ? `<tr><td style="padding:0 32px 28px">${footer}</td></tr>` : ''}
|
|
572
|
+
</table>
|
|
573
|
+
<!--[if mso]></td></tr></table><![endif]-->
|
|
574
|
+
</td></tr></table></body></html>`
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export type RenderedEmail = { subject: string; html: string; text: string }
|
|
578
|
+
|
|
579
|
+
/** A whole email from (validated) template data. */
|
|
580
|
+
export function renderEmail(data: TemplateData, ctx: RenderContext): RenderedEmail {
|
|
581
|
+
const root = data.root.props
|
|
582
|
+
const subject = fillText(root.subject, ctx).replace(/\s+/g, ' ').trim()
|
|
583
|
+
const html = layoutHtml(data.content.map((block) => blockHtml(block, ctx)).join(''), root, ctx, subject)
|
|
584
|
+
const text = [...data.content.map((block) => blockText(block, ctx)), root.footer ? `--\n${fillText(root.footer, ctx)}` : '']
|
|
585
|
+
.filter((part) => part.trim())
|
|
586
|
+
.join('\n\n')
|
|
587
|
+
return { subject, html, text }
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/** Colours and fonts for emails from the site's resolved light theme variables. */
|
|
591
|
+
export function emailThemeFrom(light: Record<string, string>, shared: Record<string, string>): EmailTheme {
|
|
592
|
+
const fallbackFont = 'Helvetica, Arial, sans-serif'
|
|
593
|
+
return {
|
|
594
|
+
primary: safeColor(light['--primary'] ?? '', '#e8590c'),
|
|
595
|
+
onPrimary: safeColor(light['--on-primary'] ?? '', '#ffffff'),
|
|
596
|
+
ink: safeColor(light['--ink'] ?? '', '#1f2937'),
|
|
597
|
+
muted: safeColor(light['--muted'] ?? '', '#6b7077'),
|
|
598
|
+
background: safeColor(light['--surface-alt'] ?? light['--bg'] ?? '', '#f4f4f5'),
|
|
599
|
+
surface: safeColor(light['--surface'] ?? '', '#ffffff'),
|
|
600
|
+
line: safeColor(light['--line'] ?? '', '#e5e7eb'),
|
|
601
|
+
// Web fonts rarely load in email: the theme's font first, then safe system fonts.
|
|
602
|
+
font: [shared['--font-body'], fallbackFont].filter(Boolean).join(', '),
|
|
603
|
+
headingFont: [shared['--font-heading'], fallbackFont].filter(Boolean).join(', '),
|
|
604
|
+
radius: Math.min(Math.max(Number.parseInt(shared['--radius-btn'] ?? shared['--radius'] ?? '8', 10) || 0, 0), 24),
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// --- Built-in templates ---------------------------------------------------------------------------
|
|
609
|
+
|
|
610
|
+
const heading = (id: string, text: string): BlockData => ({ type: 'Heading', props: { id, text, level: 'h1', align: 'left' } })
|
|
611
|
+
const text = (id: string, value: string, size: 'normal' | 'small' = 'normal'): BlockData => ({ type: 'Text', props: { id, text: value, align: 'left', size } })
|
|
612
|
+
const button = (id: string, label: string, url: string): BlockData => ({ type: 'Button', props: { id, label, url, align: 'left', style: 'solid' } })
|
|
613
|
+
|
|
614
|
+
const FOOTER = 'Sent by {{siteName}} · {{siteUrl}}'
|
|
615
|
+
/** The logo as templates have always had it: shown, medium, centred, no link, no name. */
|
|
616
|
+
export const LOGO_DEFAULTS = { showLogo: true, logoSize: 'medium', logoAlign: 'center', logoLink: false, showSiteName: false, logoLayout: 'horizontal' } as const
|
|
617
|
+
|
|
618
|
+
/** What each purpose sends when no template of that purpose is marked as the default. */
|
|
619
|
+
export const DEFAULT_TEMPLATES: Record<EmailPurpose, TemplateData> = {
|
|
620
|
+
'password-reset': {
|
|
621
|
+
root: { props: { subject: 'Reset your {{siteName}} password', preheader: 'Choose a new password within {{minutes}} minutes.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
622
|
+
content: [
|
|
623
|
+
heading('heading-1', 'Reset your password'),
|
|
624
|
+
text('text-1', 'Hello {{name}},\n\nSomeone asked to reset the password of your {{siteName}} account. To choose a new one, use this link within {{minutes}} minutes:'),
|
|
625
|
+
button('button-1', 'Choose a new password', '{{resetLink}}'),
|
|
626
|
+
text('text-2', 'The link works once. If you did not ask for this, ignore this email: your password stays the same.', 'small'),
|
|
627
|
+
],
|
|
628
|
+
},
|
|
629
|
+
invite: {
|
|
630
|
+
root: { props: { subject: 'You’re invited to {{siteName}}', preheader: '{{inviterName}} added you as {{role}}. Choose your password within {{days}} days.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
631
|
+
content: [
|
|
632
|
+
heading('heading-1', 'Welcome to {{siteName}}'),
|
|
633
|
+
text('text-1', 'Hello {{name}},\n\n{{inviterName}} added you to the {{siteName}} admin as {{role}}. To start, choose your password with this link within {{days}} days:'),
|
|
634
|
+
button('button-1', 'Choose your password', '{{inviteLink}}'),
|
|
635
|
+
text('text-2', 'The link works once. If you were not expecting this, you can ignore this email.', 'small'),
|
|
636
|
+
],
|
|
637
|
+
},
|
|
638
|
+
'email-verify': {
|
|
639
|
+
root: { props: { subject: 'Confirm your email for {{siteName}}', preheader: 'One click, within {{hours}} hours.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
640
|
+
content: [
|
|
641
|
+
heading('heading-1', 'Confirm your email'),
|
|
642
|
+
text('text-1', 'Hello {{name}},\n\nTo make changes in the {{siteName}} admin, confirm that this is your email address. Use this link within {{hours}} hours:'),
|
|
643
|
+
button('button-1', 'Confirm my email', '{{confirmLink}}'),
|
|
644
|
+
text('text-2', 'If you did not ask for this, ignore this email.', 'small'),
|
|
645
|
+
],
|
|
646
|
+
},
|
|
647
|
+
'email-change': {
|
|
648
|
+
root: { props: { subject: 'Confirm your new email for {{siteName}}', preheader: 'Confirm {{newEmail}} within {{hours}} hours.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
649
|
+
content: [
|
|
650
|
+
heading('heading-1', 'Confirm your new email'),
|
|
651
|
+
text('text-1', 'Hello {{name}},\n\nYou asked to sign in to {{siteName}} with {{newEmail}} from now on. To confirm it, use this link within {{hours}} hours:'),
|
|
652
|
+
button('button-1', 'Confirm my new email', '{{confirmLink}}'),
|
|
653
|
+
text('text-2', 'Until you confirm, your old email keeps working. If you did not ask for this, ignore this email.', 'small'),
|
|
654
|
+
],
|
|
655
|
+
},
|
|
656
|
+
'email-changed': {
|
|
657
|
+
root: { props: { subject: 'Your {{siteName}} sign-in email is changing', preheader: 'From {{oldEmail}} to {{newEmail}}.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
658
|
+
content: [
|
|
659
|
+
heading('heading-1', 'Your sign-in email is changing'),
|
|
660
|
+
text('text-1', 'Hello {{name}},\n\nA change of the email you sign in to {{siteName}} with, from {{oldEmail}} to {{newEmail}}, was asked for by {{changedBy}}.'),
|
|
661
|
+
text('text-2', 'If you did not expect this, contact an admin of {{siteName}} straight away and change your password.', 'small'),
|
|
662
|
+
],
|
|
663
|
+
},
|
|
664
|
+
'account-deletion': {
|
|
665
|
+
root: { props: { subject: 'Your {{siteName}} account will be deleted', preheader: 'It is closed now and will be deleted on {{date}}.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
666
|
+
content: [
|
|
667
|
+
heading('heading-1', 'Your account is closed'),
|
|
668
|
+
text('text-1', 'Hello {{name}},\n\nAs you asked, your {{siteName}} account is closed: you are signed out and cannot sign in. It will be deleted for good on {{date}}, in {{days}} days. Your name will then be removed from the site’s activity log too.'),
|
|
669
|
+
text('text-2', 'Changed your mind? Ask an admin of {{siteName}} to restore your account before {{date}}.', 'small'),
|
|
670
|
+
],
|
|
671
|
+
},
|
|
672
|
+
test: {
|
|
673
|
+
root: { props: { subject: 'Test email from {{siteName}}', preheader: 'The site can send email.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
674
|
+
content: [
|
|
675
|
+
heading('heading-1', 'It works'),
|
|
676
|
+
text('text-1', 'This is a test email from {{siteName}}, sent by {{senderName}} from the admin. If you can read it, the site can send email, for example password reset links.'),
|
|
677
|
+
],
|
|
678
|
+
},
|
|
679
|
+
'team-notification': {
|
|
680
|
+
root: { props: { subject: 'New: {{title}}', preheader: 'Something new on {{siteName}}: {{title}}.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
681
|
+
content: [
|
|
682
|
+
heading('heading-1', 'New: {{title}}'),
|
|
683
|
+
text('text-1', 'Something new came in on {{siteName}}. The details:'),
|
|
684
|
+
{ type: 'Details', props: { id: 'details-1', title: '' } },
|
|
685
|
+
],
|
|
686
|
+
},
|
|
687
|
+
'visitor-message': {
|
|
688
|
+
root: { props: { subject: 'Thanks, we got your message', preheader: 'We received your {{title}}.', ...LOGO_DEFAULTS, footer: FOOTER } },
|
|
689
|
+
content: [heading('heading-1', 'Thank you'), text('text-1', 'We received your “{{title}}” and will get back to you soon.\n\n{{siteName}}')],
|
|
690
|
+
},
|
|
691
|
+
}
|