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.
Files changed (486) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -0
  3. package/index.js +920 -0
  4. package/package.json +43 -1
  5. package/template/.env.example +136 -0
  6. package/template/.pet-adopt/template.json +581 -0
  7. package/template/LICENSE +21 -0
  8. package/template/README.md +109 -0
  9. package/template/_gitignore +28 -0
  10. package/template/_pnpm-lock.yaml +9251 -0
  11. package/template/assets/sample-pet.png +0 -0
  12. package/template/components.json +25 -0
  13. package/template/docker-compose.yml +110 -0
  14. package/template/drizzle/pg/0000_initial.sql +176 -0
  15. package/template/drizzle/pg/0001_greedy_the_renegades.sql +1 -0
  16. package/template/drizzle/pg/0002_fuzzy_the_renegades.sql +1 -0
  17. package/template/drizzle/pg/0003_thin_multiple_man.sql +1 -0
  18. package/template/drizzle/pg/0004_boring_norman_osborn.sql +15 -0
  19. package/template/drizzle/pg/0005_bitter_proemial_gods.sql +3 -0
  20. package/template/drizzle/pg/0006_friendly_black_knight.sql +2 -0
  21. package/template/drizzle/pg/0007_wise_ozymandias.sql +11 -0
  22. package/template/drizzle/pg/0008_messy_human_fly.sql +2 -0
  23. package/template/drizzle/pg/0009_amused_lady_bullseye.sql +1 -0
  24. package/template/drizzle/pg/0010_cute_mauler.sql +7 -0
  25. package/template/drizzle/pg/0011_clear_purple_man.sql +3 -0
  26. package/template/drizzle/pg/0012_tiresome_gunslinger.sql +2 -0
  27. package/template/drizzle/pg/0013_awesome_wong.sql +18 -0
  28. package/template/drizzle/pg/0014_fantastic_sumo.sql +12 -0
  29. package/template/drizzle/pg/0015_pink_carnage.sql +12 -0
  30. package/template/drizzle/pg/0016_sloppy_king_bedlam.sql +2 -0
  31. package/template/drizzle/pg/0017_steep_warhawk.sql +15 -0
  32. package/template/drizzle/pg/0018_mixed_otto_octavius.sql +4 -0
  33. package/template/drizzle/pg/0019_talented_rocket_raccoon.sql +1 -0
  34. package/template/drizzle/pg/0020_worthless_zodiak.sql +19 -0
  35. package/template/drizzle/pg/0021_adorable_squadron_supreme.sql +1 -0
  36. package/template/drizzle/pg/0022_soft_pixie.sql +5 -0
  37. package/template/drizzle/pg/0023_fluffy_quasar.sql +1 -0
  38. package/template/drizzle/pg/0024_uneven_ken_ellis.sql +2 -0
  39. package/template/drizzle/pg/0025_rich_white_queen.sql +3 -0
  40. package/template/drizzle/pg/0026_spooky_komodo.sql +16 -0
  41. package/template/drizzle/pg/0027_big_thunderbolts.sql +2 -0
  42. package/template/drizzle/pg/meta/0000_snapshot.json +1265 -0
  43. package/template/drizzle/pg/meta/0001_snapshot.json +1272 -0
  44. package/template/drizzle/pg/meta/0002_snapshot.json +1278 -0
  45. package/template/drizzle/pg/meta/0003_snapshot.json +1284 -0
  46. package/template/drizzle/pg/meta/0004_snapshot.json +1401 -0
  47. package/template/drizzle/pg/meta/0005_snapshot.json +1401 -0
  48. package/template/drizzle/pg/meta/0006_snapshot.json +1414 -0
  49. package/template/drizzle/pg/meta/0007_snapshot.json +1485 -0
  50. package/template/drizzle/pg/meta/0008_snapshot.json +1504 -0
  51. package/template/drizzle/pg/meta/0009_snapshot.json +1510 -0
  52. package/template/drizzle/pg/meta/0010_snapshot.json +1556 -0
  53. package/template/drizzle/pg/meta/0011_snapshot.json +1574 -0
  54. package/template/drizzle/pg/meta/0012_snapshot.json +1586 -0
  55. package/template/drizzle/pg/meta/0013_snapshot.json +1730 -0
  56. package/template/drizzle/pg/meta/0014_snapshot.json +1805 -0
  57. package/template/drizzle/pg/meta/0015_snapshot.json +1883 -0
  58. package/template/drizzle/pg/meta/0016_snapshot.json +1897 -0
  59. package/template/drizzle/pg/meta/0017_snapshot.json +2013 -0
  60. package/template/drizzle/pg/meta/0018_snapshot.json +1988 -0
  61. package/template/drizzle/pg/meta/0019_snapshot.json +1994 -0
  62. package/template/drizzle/pg/meta/0020_snapshot.json +2108 -0
  63. package/template/drizzle/pg/meta/0021_snapshot.json +2114 -0
  64. package/template/drizzle/pg/meta/0022_snapshot.json +2126 -0
  65. package/template/drizzle/pg/meta/0023_snapshot.json +2132 -0
  66. package/template/drizzle/pg/meta/0024_snapshot.json +2151 -0
  67. package/template/drizzle/pg/meta/0025_snapshot.json +2169 -0
  68. package/template/drizzle/pg/meta/0026_snapshot.json +2294 -0
  69. package/template/drizzle/pg/meta/0027_snapshot.json +2330 -0
  70. package/template/drizzle/pg/meta/_journal.json +202 -0
  71. package/template/drizzle/sqlite/0000_initial.sql +176 -0
  72. package/template/drizzle/sqlite/0001_easy_sebastian_shaw.sql +1 -0
  73. package/template/drizzle/sqlite/0002_past_king_cobra.sql +1 -0
  74. package/template/drizzle/sqlite/0003_organic_masked_marvel.sql +1 -0
  75. package/template/drizzle/sqlite/0004_panoramic_inhumans.sql +15 -0
  76. package/template/drizzle/sqlite/0005_small_sunset_bain.sql +19 -0
  77. package/template/drizzle/sqlite/0006_narrow_medusa.sql +2 -0
  78. package/template/drizzle/sqlite/0007_gray_grandmaster.sql +10 -0
  79. package/template/drizzle/sqlite/0008_chief_toxin.sql +1 -0
  80. package/template/drizzle/sqlite/0009_vengeful_tag.sql +1 -0
  81. package/template/drizzle/sqlite/0010_kind_klaw.sql +7 -0
  82. package/template/drizzle/sqlite/0011_overrated_meltdown.sql +3 -0
  83. package/template/drizzle/sqlite/0012_robust_next_avengers.sql +2 -0
  84. package/template/drizzle/sqlite/0013_melodic_kitty_pryde.sql +18 -0
  85. package/template/drizzle/sqlite/0014_stormy_cyclops.sql +12 -0
  86. package/template/drizzle/sqlite/0015_parallel_mongu.sql +11 -0
  87. package/template/drizzle/sqlite/0016_grey_quicksilver.sql +2 -0
  88. package/template/drizzle/sqlite/0017_daily_psylocke.sql +15 -0
  89. package/template/drizzle/sqlite/0018_whole_redwing.sql +4 -0
  90. package/template/drizzle/sqlite/0019_spotty_mandroid.sql +1 -0
  91. package/template/drizzle/sqlite/0020_wild_wendell_rand.sql +19 -0
  92. package/template/drizzle/sqlite/0021_calm_lockheed.sql +1 -0
  93. package/template/drizzle/sqlite/0022_lonely_emma_frost.sql +5 -0
  94. package/template/drizzle/sqlite/0023_elite_tony_stark.sql +1 -0
  95. package/template/drizzle/sqlite/0024_little_lily_hollister.sql +1 -0
  96. package/template/drizzle/sqlite/0025_tough_shotgun.sql +3 -0
  97. package/template/drizzle/sqlite/0026_faithful_mephistopheles.sql +16 -0
  98. package/template/drizzle/sqlite/0027_rapid_arclight.sql +2 -0
  99. package/template/drizzle/sqlite/meta/0000_snapshot.json +1237 -0
  100. package/template/drizzle/sqlite/meta/0001_snapshot.json +1245 -0
  101. package/template/drizzle/sqlite/meta/0002_snapshot.json +1252 -0
  102. package/template/drizzle/sqlite/meta/0003_snapshot.json +1259 -0
  103. package/template/drizzle/sqlite/meta/0004_snapshot.json +1369 -0
  104. package/template/drizzle/sqlite/meta/0005_snapshot.json +1369 -0
  105. package/template/drizzle/sqlite/meta/0006_snapshot.json +1384 -0
  106. package/template/drizzle/sqlite/meta/0007_snapshot.json +1459 -0
  107. package/template/drizzle/sqlite/meta/0008_snapshot.json +1479 -0
  108. package/template/drizzle/sqlite/meta/0009_snapshot.json +1486 -0
  109. package/template/drizzle/sqlite/meta/0010_snapshot.json +1533 -0
  110. package/template/drizzle/sqlite/meta/0011_snapshot.json +1554 -0
  111. package/template/drizzle/sqlite/meta/0012_snapshot.json +1568 -0
  112. package/template/drizzle/sqlite/meta/0013_snapshot.json +1687 -0
  113. package/template/drizzle/sqlite/meta/0014_snapshot.json +1769 -0
  114. package/template/drizzle/sqlite/meta/0015_snapshot.json +1852 -0
  115. package/template/drizzle/sqlite/meta/0016_snapshot.json +1867 -0
  116. package/template/drizzle/sqlite/meta/0017_snapshot.json +1973 -0
  117. package/template/drizzle/sqlite/meta/0018_snapshot.json +1944 -0
  118. package/template/drizzle/sqlite/meta/0019_snapshot.json +1951 -0
  119. package/template/drizzle/sqlite/meta/0020_snapshot.json +2077 -0
  120. package/template/drizzle/sqlite/meta/0021_snapshot.json +2084 -0
  121. package/template/drizzle/sqlite/meta/0022_snapshot.json +2098 -0
  122. package/template/drizzle/sqlite/meta/0023_snapshot.json +2105 -0
  123. package/template/drizzle/sqlite/meta/0024_snapshot.json +2125 -0
  124. package/template/drizzle/sqlite/meta/0025_snapshot.json +2146 -0
  125. package/template/drizzle/sqlite/meta/0026_snapshot.json +2265 -0
  126. package/template/drizzle/sqlite/meta/0027_snapshot.json +2280 -0
  127. package/template/drizzle/sqlite/meta/_journal.json +202 -0
  128. package/template/drizzle.pg.config.ts +8 -0
  129. package/template/drizzle.sqlite.config.ts +8 -0
  130. package/template/eslint.config.mjs +22 -0
  131. package/template/next.config.ts +153 -0
  132. package/template/package.json +102 -0
  133. package/template/pet-adopt.blocks.ts +9 -0
  134. package/template/pet-adopt.config.ts +17 -0
  135. package/template/pnpm-workspace.yaml +19 -0
  136. package/template/postcss.config.mjs +5 -0
  137. package/template/scripts/check-routes.ts +405 -0
  138. package/template/scripts/check-schemas.ts +58 -0
  139. package/template/scripts/migrate-all.ts +25 -0
  140. package/template/scripts/migrate-on-build.ts +71 -0
  141. package/template/scripts/migrate.ts +20 -0
  142. package/template/scripts/plugin-generate.ts +92 -0
  143. package/template/scripts/reset-password.ts +45 -0
  144. package/template/scripts/reset-two-factor.ts +53 -0
  145. package/template/scripts/seed.ts +79 -0
  146. package/template/scripts/setup-env.ts +91 -0
  147. package/template/scripts/storage-check.ts +53 -0
  148. package/template/src/app/(admin)/admin/account/AccountForms.tsx +194 -0
  149. package/template/src/app/(admin)/admin/account/page.tsx +59 -0
  150. package/template/src/app/(admin)/admin/activity/page.tsx +76 -0
  151. package/template/src/app/(admin)/admin/authentication/archived/page.tsx +24 -0
  152. package/template/src/app/(admin)/admin/authentication/layout.tsx +20 -0
  153. package/template/src/app/(admin)/admin/authentication/page.tsx +36 -0
  154. package/template/src/app/(admin)/admin/authentication/providers/page.tsx +33 -0
  155. package/template/src/app/(admin)/admin/email/layout.tsx +21 -0
  156. package/template/src/app/(admin)/admin/email/page.tsx +43 -0
  157. package/template/src/app/(admin)/admin/email/templates/page.tsx +38 -0
  158. package/template/src/app/(admin)/admin/error.tsx +36 -0
  159. package/template/src/app/(admin)/admin/layout.tsx +26 -0
  160. package/template/src/app/(admin)/admin/loading.tsx +9 -0
  161. package/template/src/app/(admin)/admin/media/[id]/page.tsx +97 -0
  162. package/template/src/app/(admin)/admin/media/page.tsx +34 -0
  163. package/template/src/app/(admin)/admin/media/search-params.ts +16 -0
  164. package/template/src/app/(admin)/admin/page.tsx +79 -0
  165. package/template/src/app/(admin)/admin/pages/PageForm.tsx +604 -0
  166. package/template/src/app/(admin)/admin/pages/[id]/page.tsx +51 -0
  167. package/template/src/app/(admin)/admin/pages/new/page.tsx +19 -0
  168. package/template/src/app/(admin)/admin/pages/page.tsx +49 -0
  169. package/template/src/app/(admin)/admin/pets/PetForm.tsx +437 -0
  170. package/template/src/app/(admin)/admin/pets/[id]/page.tsx +41 -0
  171. package/template/src/app/(admin)/admin/pets/new/page.tsx +26 -0
  172. package/template/src/app/(admin)/admin/pets/page.tsx +70 -0
  173. package/template/src/app/(admin)/admin/pets/search-params.ts +16 -0
  174. package/template/src/app/(admin)/admin/plugins/[plugin]/[[...path]]/page.tsx +73 -0
  175. package/template/src/app/(admin)/admin/plugins/page.tsx +66 -0
  176. package/template/src/app/(admin)/admin/settings/SettingsForm.tsx +644 -0
  177. package/template/src/app/(admin)/admin/settings/email/page.tsx +9 -0
  178. package/template/src/app/(admin)/admin/settings/page.tsx +40 -0
  179. package/template/src/app/(admin)/admin/settings/templates/page.tsx +9 -0
  180. package/template/src/app/(admin)/admin/theme/[id]/page.tsx +28 -0
  181. package/template/src/app/(admin)/admin/theme/page.tsx +30 -0
  182. package/template/src/app/(admin)/admin/users/page.tsx +33 -0
  183. package/template/src/app/(admin)/layout.tsx +75 -0
  184. package/template/src/app/(admin)/providers.tsx +42 -0
  185. package/template/src/app/(auth)/admin/confirm-email/page.tsx +40 -0
  186. package/template/src/app/(auth)/admin/invite/page.tsx +38 -0
  187. package/template/src/app/(auth)/admin/login/DemoSignIn.tsx +69 -0
  188. package/template/src/app/(auth)/admin/login/page.tsx +83 -0
  189. package/template/src/app/(auth)/admin/reset-password/page.tsx +73 -0
  190. package/template/src/app/(auth)/error.tsx +9 -0
  191. package/template/src/app/(auth)/layout.tsx +71 -0
  192. package/template/src/app/(editor)/EditorToast.tsx +43 -0
  193. package/template/src/app/(editor)/edit/[id]/PageEditor.tsx +586 -0
  194. package/template/src/app/(editor)/edit/[id]/actions.ts +139 -0
  195. package/template/src/app/(editor)/edit/[id]/page.tsx +76 -0
  196. package/template/src/app/(editor)/edit/[id]/preview/page.tsx +81 -0
  197. package/template/src/app/(editor)/edit/email/[id]/EmailEditor.tsx +236 -0
  198. package/template/src/app/(editor)/edit/email/[id]/page.tsx +64 -0
  199. package/template/src/app/(editor)/edit/theme-preview/page.tsx +94 -0
  200. package/template/src/app/(editor)/editor.css +223 -0
  201. package/template/src/app/(editor)/error.tsx +32 -0
  202. package/template/src/app/(editor)/layout.tsx +67 -0
  203. package/template/src/app/(frontend)/[slug]/page.tsx +53 -0
  204. package/template/src/app/(frontend)/fonts.ts +8 -0
  205. package/template/src/app/(frontend)/layout.tsx +107 -0
  206. package/template/src/app/(frontend)/not-found.tsx +16 -0
  207. package/template/src/app/(frontend)/page.tsx +42 -0
  208. package/template/src/app/(frontend)/pets/[slug]/page.tsx +92 -0
  209. package/template/src/app/(frontend)/pets/page.tsx +42 -0
  210. package/template/src/app/(frontend)/styles.css +537 -0
  211. package/template/src/app/(setup)/error.tsx +9 -0
  212. package/template/src/app/(setup)/layout.tsx +41 -0
  213. package/template/src/app/(setup)/setup/page.tsx +105 -0
  214. package/template/src/app/(setup)/setup/storage-check.ts +43 -0
  215. package/template/src/app/api/auth/[...all]/route.ts +144 -0
  216. package/template/src/app/health/route.ts +9 -0
  217. package/template/src/app/media/[...path]/route.ts +45 -0
  218. package/template/src/app/media/email/[name]/route.ts +60 -0
  219. package/template/src/app/robots.ts +19 -0
  220. package/template/src/app/sitemap.ts +24 -0
  221. package/template/src/components/admin/AdminNav.tsx +153 -0
  222. package/template/src/components/admin/AdminShell.tsx +107 -0
  223. package/template/src/components/admin/DemoNotice.tsx +31 -0
  224. package/template/src/components/admin/EmailConfirmBanner.tsx +44 -0
  225. package/template/src/components/admin/EmptyState.tsx +10 -0
  226. package/template/src/components/admin/ErrorSummary.tsx +72 -0
  227. package/template/src/components/admin/MediaDetails.tsx +218 -0
  228. package/template/src/components/admin/MediaGrid.tsx +307 -0
  229. package/template/src/components/admin/MediaLibrary.tsx +103 -0
  230. package/template/src/components/admin/MediaPager.tsx +66 -0
  231. package/template/src/components/admin/PageHeader.tsx +22 -0
  232. package/template/src/components/admin/PhoneInput.tsx +128 -0
  233. package/template/src/components/admin/PluginWidgetBoundary.tsx +38 -0
  234. package/template/src/components/admin/PluginWidgets.tsx +51 -0
  235. package/template/src/components/admin/RemountOnNavigate.tsx +37 -0
  236. package/template/src/components/admin/StatusBadge.tsx +16 -0
  237. package/template/src/components/admin/UploadPhotosDialog.tsx +387 -0
  238. package/template/src/components/admin/UserAvatar.tsx +18 -0
  239. package/template/src/components/admin/UserMenu.tsx +118 -0
  240. package/template/src/components/admin/ViewSiteLink.tsx +24 -0
  241. package/template/src/components/admin/account/ConnectedProviders.tsx +91 -0
  242. package/template/src/components/admin/account/DeleteAccountCard.tsx +136 -0
  243. package/template/src/components/admin/account/EmailCard.tsx +137 -0
  244. package/template/src/components/admin/account/ProfilePicture.tsx +159 -0
  245. package/template/src/components/admin/activity/ActivityFilters.tsx +146 -0
  246. package/template/src/components/admin/activity/ActivityLog.tsx +159 -0
  247. package/template/src/components/admin/activity/RecentActivity.tsx +52 -0
  248. package/template/src/components/admin/demo-mode.tsx +17 -0
  249. package/template/src/components/admin/nav-items.ts +47 -0
  250. package/template/src/components/admin/pages/PageDetails.tsx +198 -0
  251. package/template/src/components/admin/pages/PageVersions.tsx +296 -0
  252. package/template/src/components/admin/pages/PagesTable.tsx +467 -0
  253. package/template/src/components/admin/pets/FilterBar.tsx +154 -0
  254. package/template/src/components/admin/pets/PetCard.tsx +170 -0
  255. package/template/src/components/admin/pets/PetList.tsx +112 -0
  256. package/template/src/components/admin/pets/PetListSkeleton.tsx +84 -0
  257. package/template/src/components/admin/pets/PetPagination.tsx +91 -0
  258. package/template/src/components/admin/pets/form/AgeFields.tsx +132 -0
  259. package/template/src/components/admin/pets/form/LocationFields.tsx +231 -0
  260. package/template/src/components/admin/pets/form/MediaPickerDialog.tsx +359 -0
  261. package/template/src/components/admin/pets/form/PhotosField.tsx +176 -0
  262. package/template/src/components/admin/pets/form/RichTextField.tsx +438 -0
  263. package/template/src/components/admin/pets/form/SeoImageField.tsx +87 -0
  264. package/template/src/components/admin/pets/form/SeoPreview.tsx +142 -0
  265. package/template/src/components/admin/pets/form/fields.tsx +434 -0
  266. package/template/src/components/admin/pets/form/rich-text-extensions.ts +45 -0
  267. package/template/src/components/admin/pets/timeline/PetTimeline.tsx +297 -0
  268. package/template/src/components/admin/pets/timeline/TimelineEntryForm.tsx +289 -0
  269. package/template/src/components/admin/pets/timeline/TimelinePhotosField.tsx +173 -0
  270. package/template/src/components/admin/plugins/PluginNotReady.tsx +28 -0
  271. package/template/src/components/admin/plugins/PluginOverview.tsx +121 -0
  272. package/template/src/components/admin/plugins/SendTestEmail.tsx +70 -0
  273. package/template/src/components/admin/settings/AuthProviders.tsx +373 -0
  274. package/template/src/components/admin/settings/AuthenticationNav.tsx +42 -0
  275. package/template/src/components/admin/settings/EmailNav.tsx +40 -0
  276. package/template/src/components/admin/settings/EmailSettingsForm.tsx +325 -0
  277. package/template/src/components/admin/settings/EmailTemplates.tsx +551 -0
  278. package/template/src/components/admin/settings/RegionFields.tsx +203 -0
  279. package/template/src/components/admin/site-time.tsx +26 -0
  280. package/template/src/components/admin/theme/ThemeEditor.tsx +467 -0
  281. package/template/src/components/admin/theme/ThemeLibrary.tsx +339 -0
  282. package/template/src/components/admin/theme/ThemeSwatches.tsx +30 -0
  283. package/template/src/components/admin/theme/theme-utils.ts +32 -0
  284. package/template/src/components/admin/two-factor/BackupCodeList.tsx +54 -0
  285. package/template/src/components/admin/two-factor/TwoFactorCard.tsx +237 -0
  286. package/template/src/components/admin/two-factor/TwoFactorRequired.tsx +52 -0
  287. package/template/src/components/admin/two-factor/TwoFactorSetup.tsx +180 -0
  288. package/template/src/components/admin/use-unsaved-changes.tsx +101 -0
  289. package/template/src/components/admin/users/ArchivedAccounts.tsx +159 -0
  290. package/template/src/components/admin/users/InviteDialogs.tsx +131 -0
  291. package/template/src/components/admin/users/TwoFactorRoles.tsx +80 -0
  292. package/template/src/components/admin/users/UserDialogs.tsx +681 -0
  293. package/template/src/components/admin/users/UsersTable.tsx +374 -0
  294. package/template/src/components/admin/view-only.tsx +43 -0
  295. package/template/src/components/auth/AcceptInviteForm.tsx +123 -0
  296. package/template/src/components/auth/AuthNav.tsx +80 -0
  297. package/template/src/components/auth/ConfirmEmailForm.tsx +73 -0
  298. package/template/src/components/auth/LoginForm.tsx +250 -0
  299. package/template/src/components/auth/PageError.tsx +37 -0
  300. package/template/src/components/auth/ProviderSignIn.tsx +53 -0
  301. package/template/src/components/auth/ResetPasswordForm.tsx +267 -0
  302. package/template/src/components/demo/DemoBanner.tsx +38 -0
  303. package/template/src/components/demo/SiteDemoBanner.tsx +22 -0
  304. package/template/src/components/demo/wording.ts +21 -0
  305. package/template/src/components/setup/SetupAccountForm.tsx +93 -0
  306. package/template/src/components/setup/SetupDone.tsx +95 -0
  307. package/template/src/components/setup/SetupNav.tsx +49 -0
  308. package/template/src/components/setup/SetupSampleContent.tsx +67 -0
  309. package/template/src/components/setup/SetupSiteForm.tsx +104 -0
  310. package/template/src/components/setup/SetupThemePicker.tsx +73 -0
  311. package/template/src/components/setup/SkipSetup.tsx +35 -0
  312. package/template/src/components/site/BuilderContent.tsx +46 -0
  313. package/template/src/components/site/CopyButton.tsx +28 -0
  314. package/template/src/components/site/ImageCarousel.tsx +52 -0
  315. package/template/src/components/site/PetCard.tsx +32 -0
  316. package/template/src/components/site/PetCatalog.tsx +106 -0
  317. package/template/src/components/site/PetGallery.tsx +75 -0
  318. package/template/src/components/site/PetTimeline.tsx +82 -0
  319. package/template/src/components/site/RemountOnNavigate.tsx +13 -0
  320. package/template/src/components/site/RichText.tsx +56 -0
  321. package/template/src/components/site/SmartLink.tsx +37 -0
  322. package/template/src/components/site/SocialIcons.tsx +26 -0
  323. package/template/src/components/site/ThemePreviewBridge.tsx +29 -0
  324. package/template/src/components/site/ThemeStyle.tsx +22 -0
  325. package/template/src/components/site/ThemeToggle.tsx +36 -0
  326. package/template/src/components/site/WhatsAppButton.tsx +27 -0
  327. package/template/src/components/site/timeline-format.ts +20 -0
  328. package/template/src/db/client.ts +702 -0
  329. package/template/src/db/compare-tables.ts +41 -0
  330. package/template/src/db/migrate.ts +28 -0
  331. package/template/src/db/plugin-migrations.ts +167 -0
  332. package/template/src/db/schema/pg.ts +484 -0
  333. package/template/src/db/schema/sqlite.ts +492 -0
  334. package/template/src/instrumentation.ts +110 -0
  335. package/template/src/lib/activity.ts +29 -0
  336. package/template/src/lib/admin/call-action.ts +19 -0
  337. package/template/src/lib/admin/initials.ts +9 -0
  338. package/template/src/lib/admin/media-cache.ts +16 -0
  339. package/template/src/lib/admin/media-page.ts +3 -0
  340. package/template/src/lib/admin/pet-form.ts +242 -0
  341. package/template/src/lib/admin/pets-cache.ts +22 -0
  342. package/template/src/lib/admin/unwrap-client.ts +11 -0
  343. package/template/src/lib/admin/unwrap.ts +38 -0
  344. package/template/src/lib/admin/use-media-list.ts +41 -0
  345. package/template/src/lib/admin/use-pet-list.ts +58 -0
  346. package/template/src/lib/age.ts +117 -0
  347. package/template/src/lib/auth-provider-errors.ts +38 -0
  348. package/template/src/lib/cache.ts +69 -0
  349. package/template/src/lib/color-mode.ts +48 -0
  350. package/template/src/lib/demo.ts +78 -0
  351. package/template/src/lib/email-address.ts +9 -0
  352. package/template/src/lib/email-template.ts +691 -0
  353. package/template/src/lib/links.ts +78 -0
  354. package/template/src/lib/mail-error.ts +38 -0
  355. package/template/src/lib/media-name.ts +31 -0
  356. package/template/src/lib/options.ts +134 -0
  357. package/template/src/lib/pagination.ts +28 -0
  358. package/template/src/lib/pet-placeholders.ts +34 -0
  359. package/template/src/lib/pet-seo.ts +40 -0
  360. package/template/src/lib/pet-timeline.ts +62 -0
  361. package/template/src/lib/phone.ts +129 -0
  362. package/template/src/lib/places.ts +84 -0
  363. package/template/src/lib/queries.ts +549 -0
  364. package/template/src/lib/revalidate.ts +32 -0
  365. package/template/src/lib/rich-text.ts +215 -0
  366. package/template/src/lib/seo.ts +121 -0
  367. package/template/src/lib/slugify.ts +11 -0
  368. package/template/src/lib/theme.ts +546 -0
  369. package/template/src/lib/utils.ts +2 -0
  370. package/template/src/lib/whatsapp.ts +29 -0
  371. package/template/src/lib/zod-schema/auth.ts +56 -0
  372. package/template/src/lib/zod-schema/page.ts +57 -0
  373. package/template/src/lib/zod-schema/pet-timeline.ts +118 -0
  374. package/template/src/lib/zod-schema/pet.ts +172 -0
  375. package/template/src/lib/zod-schema/settings.ts +162 -0
  376. package/template/src/plugins/host.ts +117 -0
  377. package/template/src/plugins/icon.ts +89 -0
  378. package/template/src/plugins/registry.ts +369 -0
  379. package/template/src/plugins/storage-rules.ts +87 -0
  380. package/template/src/plugins/storage.ts +184 -0
  381. package/template/src/puck/actions.ts +46 -0
  382. package/template/src/puck/config.tsx +1693 -0
  383. package/template/src/puck/data.ts +196 -0
  384. package/template/src/puck/demo-mode.tsx +20 -0
  385. package/template/src/puck/email-config.tsx +267 -0
  386. package/template/src/puck/icons.tsx +76 -0
  387. package/template/src/puck/media-picker.tsx +273 -0
  388. package/template/src/puck/padding.tsx +71 -0
  389. package/template/src/puck/pet-page-config.tsx +511 -0
  390. package/template/src/puck/pet-picker.tsx +40 -0
  391. package/template/src/puck/plugin-block-data.ts +91 -0
  392. package/template/src/puck/plugin-blocks.tsx +235 -0
  393. package/template/src/puck/plugin-choice-field.tsx +87 -0
  394. package/template/src/puck/sanitize.ts +107 -0
  395. package/template/src/puck/server.ts +36 -0
  396. package/template/src/puck/types.ts +41 -0
  397. package/template/src/server/actions/activity.ts +48 -0
  398. package/template/src/server/actions/auth-providers.ts +171 -0
  399. package/template/src/server/actions/auth.ts +217 -0
  400. package/template/src/server/actions/demo.ts +30 -0
  401. package/template/src/server/actions/email-change.ts +80 -0
  402. package/template/src/server/actions/email-templates.ts +144 -0
  403. package/template/src/server/actions/email.ts +70 -0
  404. package/template/src/server/actions/media.ts +127 -0
  405. package/template/src/server/actions/pages.ts +159 -0
  406. package/template/src/server/actions/password-reset.ts +80 -0
  407. package/template/src/server/actions/pet-timeline.ts +75 -0
  408. package/template/src/server/actions/pets.ts +74 -0
  409. package/template/src/server/actions/places.ts +36 -0
  410. package/template/src/server/actions/settings.ts +29 -0
  411. package/template/src/server/actions/setup.ts +72 -0
  412. package/template/src/server/actions/themes.ts +80 -0
  413. package/template/src/server/actions/two-factor.ts +306 -0
  414. package/template/src/server/actions/users.ts +200 -0
  415. package/template/src/server/activity.ts +409 -0
  416. package/template/src/server/auth-errors.ts +17 -0
  417. package/template/src/server/auth-providers.ts +359 -0
  418. package/template/src/server/auth.ts +266 -0
  419. package/template/src/server/avatars.ts +263 -0
  420. package/template/src/server/demo-site.ts +169 -0
  421. package/template/src/server/email-change.ts +278 -0
  422. package/template/src/server/email-templates.ts +350 -0
  423. package/template/src/server/email.ts +442 -0
  424. package/template/src/server/invites.ts +143 -0
  425. package/template/src/server/media-url.ts +20 -0
  426. package/template/src/server/media.ts +236 -0
  427. package/template/src/server/pages.ts +812 -0
  428. package/template/src/server/password-reset.ts +158 -0
  429. package/template/src/server/pending-links.ts +46 -0
  430. package/template/src/server/pet-timeline.ts +181 -0
  431. package/template/src/server/pets.ts +555 -0
  432. package/template/src/server/places.ts +113 -0
  433. package/template/src/server/privacy.ts +21 -0
  434. package/template/src/server/provider-endpoints.ts +94 -0
  435. package/template/src/server/provider-guard.ts +157 -0
  436. package/template/src/server/result.ts +280 -0
  437. package/template/src/server/sample-content.ts +368 -0
  438. package/template/src/server/search-text.ts +43 -0
  439. package/template/src/server/secret-box.ts +38 -0
  440. package/template/src/server/session.ts +154 -0
  441. package/template/src/server/settings.ts +361 -0
  442. package/template/src/server/setup.ts +110 -0
  443. package/template/src/server/sitemap.ts +88 -0
  444. package/template/src/server/storage.ts +267 -0
  445. package/template/src/server/strip-metadata.ts +357 -0
  446. package/template/src/server/themes.ts +195 -0
  447. package/template/src/server/throttle.ts +258 -0
  448. package/template/src/server/two-factor-codes.ts +32 -0
  449. package/template/src/server/two-factor.ts +158 -0
  450. package/template/src/server/types.ts +198 -0
  451. package/template/src/server/uploads.ts +137 -0
  452. package/template/src/server/users.ts +500 -0
  453. package/template/tsconfig.json +44 -0
  454. package/template/ui/components.json +25 -0
  455. package/template/ui/package.json +12 -0
  456. package/template/ui/src/components/alert-dialog.tsx +187 -0
  457. package/template/ui/src/components/avatar.tsx +108 -0
  458. package/template/ui/src/components/badge.tsx +51 -0
  459. package/template/ui/src/components/button.tsx +57 -0
  460. package/template/ui/src/components/card.tsx +102 -0
  461. package/template/ui/src/components/carousel.tsx +245 -0
  462. package/template/ui/src/components/checkbox.tsx +27 -0
  463. package/template/ui/src/components/combobox.tsx +297 -0
  464. package/template/ui/src/components/dialog.tsx +159 -0
  465. package/template/ui/src/components/dropdown-menu.tsx +265 -0
  466. package/template/ui/src/components/field.tsx +238 -0
  467. package/template/ui/src/components/input-group.tsx +158 -0
  468. package/template/ui/src/components/input.tsx +19 -0
  469. package/template/ui/src/components/label.tsx +19 -0
  470. package/template/ui/src/components/pagination.tsx +127 -0
  471. package/template/ui/src/components/popover.tsx +89 -0
  472. package/template/ui/src/components/radio-group.tsx +37 -0
  473. package/template/ui/src/components/select.tsx +200 -0
  474. package/template/ui/src/components/separator.tsx +24 -0
  475. package/template/ui/src/components/sheet.tsx +138 -0
  476. package/template/ui/src/components/sidebar.tsx +723 -0
  477. package/template/ui/src/components/skeleton.tsx +13 -0
  478. package/template/ui/src/components/switch.tsx +31 -0
  479. package/template/ui/src/components/table.tsx +115 -0
  480. package/template/ui/src/components/tabs.tsx +81 -0
  481. package/template/ui/src/components/textarea.tsx +17 -0
  482. package/template/ui/src/components/toggle.tsx +44 -0
  483. package/template/ui/src/components/tooltip.tsx +65 -0
  484. package/template/ui/src/hooks/use-mobile.ts +21 -0
  485. package/template/ui/src/lib/utils.ts +2 -0
  486. package/template/ui/src/styles/globals.css +145 -0
@@ -0,0 +1,368 @@
1
+ // Sample content: example pets (with pictures made from a cat silhouette in the site's colours) and
2
+ // an About page, so a fresh site has
3
+ // something to look at. Used by `pnpm seed` and by the first-time setup's "Sample content" step
4
+ // (src/server/setup.ts). Every step checks first, so running it again is safe; it never adds sample
5
+ // pets next to real ones. removeSampleContent takes them out again.
6
+ import { readFile } from 'node:fs/promises'
7
+ import path from 'node:path'
8
+
9
+ import { count, eq, inArray, max } from 'drizzle-orm'
10
+ import { isEqual } from 'es-toolkit'
11
+ import sharp from 'sharp'
12
+
13
+ import { getDatabase } from '@/db/client'
14
+ import { PetStatus } from '@/lib/options'
15
+ import { slugify } from '@/lib/slugify'
16
+ import { mix, resolveTheme } from '@/lib/theme'
17
+
18
+ import { deletePage, publishPage, savePageDetails, archivePage } from './pages'
19
+ import { deletePet, savePet } from './pets'
20
+ import { isUserError, logError } from './result'
21
+ import { getSettings } from './settings'
22
+ import { removeUpload, saveUpload } from './uploads'
23
+
24
+ /**
25
+ * The sample pets' picture: a cat silhouette (a black shape on transparent, read only here, never
26
+ * served). Read from the project folder at runtime, like the migrations.
27
+ */
28
+ const SILHOUETTE = path.resolve(/* turbopackIgnore: true */ process.cwd(), 'assets', 'sample-pet.png')
29
+
30
+ /** Credit for the silhouette (Flaticon's free licence asks for it wherever the picture is used). */
31
+ const PICTURE_CREDIT = { text: 'Kitty icons created by Boris farias - Flaticon', href: 'https://www.flaticon.com/free-icons/kitty' }
32
+
33
+ /** A sample pet's description: its text, then the picture's credit as a link (rich text, not HTML). */
34
+ function describe(about: string) {
35
+ return {
36
+ type: 'doc',
37
+ content: [
38
+ { type: 'paragraph', content: [{ type: 'text', text: about }] },
39
+ {
40
+ type: 'paragraph',
41
+ content: [
42
+ { type: 'text', text: 'Picture: ' },
43
+ { type: 'text', text: PICTURE_CREDIT.text, marks: [{ type: 'link', attrs: { href: PICTURE_CREDIT.href } }] },
44
+ ],
45
+ },
46
+ ],
47
+ }
48
+ }
49
+
50
+ /**
51
+ * A sample pet's picture: the silhouette in the theme's primary colour on a soft shade of it, a
52
+ * slightly different shade per pet and every other one facing the other way, so the grid is not
53
+ * six identical tiles. 1200 x 900, like a landscape photo.
54
+ */
55
+ async function samplePicture(index: number, colors: { primary: string; bg: string }): Promise<Buffer> {
56
+ const width = 1200
57
+ const height = 900
58
+ const size = 560
59
+ const shape = await sharp(await readFile(SILHOUETTE)).resize(size, size, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } }).ensureAlpha().toBuffer()
60
+ // Fill: a block of the primary colour, kept only where the silhouette is (its alpha).
61
+ let cat = sharp({ create: { width: size, height: size, channels: 4, background: colors.primary } }).composite([{ input: shape, blend: 'dest-in' }])
62
+ if (index % 2) cat = sharp(await cat.png().toBuffer()).flop()
63
+ const shade = mix(colors.primary, colors.bg, [0.9, 0.84, 0.78][index % 3])
64
+ return sharp({ create: { width, height, channels: 4, background: shade } })
65
+ .composite([{ input: await cat.png().toBuffer(), left: (width - size) / 2, top: (height - size) / 2 }])
66
+ .png()
67
+ .toBuffer()
68
+ }
69
+
70
+ type Sample = {
71
+ name: string
72
+ species: string
73
+ breed: string
74
+ sex: string
75
+ ageGroup: string
76
+ ageDescription: string
77
+ size: string
78
+ city: string
79
+ state: string
80
+ featured: boolean
81
+ about: string
82
+ /** Defaults to available. */
83
+ status?: PetStatus
84
+ unlisted?: boolean
85
+ /** More savePet fields (temperament, health notes ...). */
86
+ extra?: Record<string, unknown>
87
+ }
88
+
89
+
90
+ /**
91
+ * Six example pets, enough to show the catalog without filling it: cats, dogs and a rabbit, every
92
+ * age group, two featured, one urgent, one with special needs, and one each pending and adopted.
93
+ */
94
+ export const samples: Sample[] = [
95
+ { name: 'Mochi', species: 'cat', breed: 'Domestic shorthair', sex: 'female', ageGroup: 'baby', ageDescription: 'about 3 months', size: 'small', city: 'Petaling Jaya', state: 'Selangor', featured: true, about: 'Playful and curious, Mochi loves feather toys and following you from room to room.' },
96
+ { name: 'Biscuit', species: 'dog', breed: 'Mixed breed', sex: 'male', ageGroup: 'young', ageDescription: '1 year', size: 'medium', city: 'Kuala Lumpur', state: 'Kuala Lumpur', featured: true, about: 'Biscuit is friendly, house-trained and great with children. He needs a family who enjoys long walks.' },
97
+ { name: 'Clover', species: 'rabbit', breed: 'Holland lop', sex: 'female', ageGroup: 'adult', ageDescription: '2 years', size: 'small', city: 'Shah Alam', state: 'Selangor', featured: false, about: 'Calm and gentle, Clover is happiest with a quiet home and plenty of fresh greens.' },
98
+ { name: 'Luna', species: 'cat', breed: 'Persian mix', sex: 'female', ageGroup: 'senior', ageDescription: '9 years', size: 'medium', city: 'Subang Jaya', state: 'Selangor', featured: false, about: 'Luna is a lap cat who wants a peaceful retirement home. Fully vaccinated and spayed.' },
99
+ { name: 'Rocky', species: 'dog', breed: 'Rottweiler mix', sex: 'male', ageGroup: 'adult', ageDescription: '4 years', size: 'large', city: 'Petaling Jaya', state: 'Selangor', featured: false, status: PetStatus.Pending, about: 'Rocky is a gentle giant. An adopter is already meeting him, so he is marked as pending.' },
100
+ { name: 'Whiskers', species: 'cat', breed: 'Siamese mix', sex: 'male', ageGroup: 'adult', ageDescription: '4 years', size: 'medium', city: 'Georgetown', state: 'Penang', featured: false, status: PetStatus.Adopted, about: 'Whiskers has found his forever home. He stays here so you can see what an adopted pet looks like.' },
101
+ ]
102
+
103
+ /**
104
+ * Sample pets of earlier versions. Not added any more, but still recognised as samples, so sites
105
+ * that have them can remove them, and they never count as real pets.
106
+ */
107
+ const RETIRED_SAMPLES = [
108
+ 'Pumpkin', 'Shadow', 'Ginger', 'Oreo', 'Tiger', 'Maple', 'Ember', 'Daisy', 'Bruno', 'Coco', 'Max', 'Bella', 'Lucky', 'Simba', 'Ziggy', 'Rusty', 'Snowball', 'Thumper', 'Olive', 'Kiwi', 'Sunny', 'Pip', 'Nibbles', 'Pebbles', 'Peanut', 'Hazel', 'Shelly',
109
+ ]
110
+
111
+ /** Every sample pet's name (current and retired) by its slug. */
112
+ const sampleNames = () => new Map([...samples.map((s) => s.name), ...RETIRED_SAMPLES].map((name) => [slugify(name), name]))
113
+
114
+ /** The alt text of a sample pet's placeholder picture (the same in every version of the samples). */
115
+ const placeholderAlt = (name: string) => `Placeholder picture for ${name}`
116
+
117
+ /**
118
+ * The sample pets on the site. A name is not enough: Bella, Max or Luna are common names for real
119
+ * pets. A sample has a sample's slug and every one of its photos is the placeholder picture made for
120
+ * it (its alt text says so). A pet whose photos the owner changed, or whose pictures were described
121
+ * again, counts as theirs and is never touched.
122
+ */
123
+ async function findSamplePets(): Promise<Array<{ id: number; slug: string; name: string; photoIds: number[] }>> {
124
+ const { db, t } = await getDatabase()
125
+ const names = sampleNames()
126
+ const candidates = await db.select({ id: t.pets.id, slug: t.pets.slug }).from(t.pets).where(inArray(t.pets.slug, [...names.keys()]))
127
+ if (!candidates.length) return []
128
+ const photos = await db
129
+ .select({ petId: t.petPhotos.petId, mediaId: t.petPhotos.mediaId, alt: t.media.alt })
130
+ .from(t.petPhotos)
131
+ .leftJoin(t.media, eq(t.media.id, t.petPhotos.mediaId))
132
+ .where(inArray(t.petPhotos.petId, candidates.map((pet) => pet.id)))
133
+ const found = []
134
+ for (const pet of candidates) {
135
+ const name = names.get(pet.slug)!
136
+ const own = photos.filter((photo) => photo.petId === pet.id)
137
+ if (own.length && own.every((photo) => photo.alt === placeholderAlt(name))) found.push({ ...pet, name, photoIds: own.map((photo) => photo.mediaId) })
138
+ }
139
+ return found
140
+ }
141
+
142
+ // Behaviour and health details for the samples, so the extra pet fields have something to show.
143
+ const extras: Record<string, Record<string, unknown>> = {
144
+ Mochi: { temperament: ['playful', 'affectionate'], goodWith: ['kids', 'cats'], houseTrained: true, microchipped: true, urgent: true, color: 'Orange tabby' },
145
+ Biscuit: { temperament: ['energetic', 'affectionate'], goodWith: ['kids', 'dogs'], houseTrained: true, microchipped: true, color: 'Brown and white' },
146
+ Clover: { temperament: ['calm', 'shy'], goodWith: ['other-pets'], houseTrained: true, color: 'Grey' },
147
+ Luna: { temperament: ['calm', 'independent'], goodWith: ['cats'], houseTrained: true, microchipped: true, specialNeeds: true, healthNotes: 'Needs a soft diet and a yearly dental check.', color: 'Cream' },
148
+ }
149
+
150
+ // "about 3 months", "10 weeks", "2 years" -> { ageValue: 3, ageUnit: 'months' }. The samples give
151
+ // their age as text; savePet stores it as an estimated birth date, so they keep ageing.
152
+ function ageFrom(text: string) {
153
+ const match = /(\d+)\s*(week|month|year)s?/.exec(text)
154
+ if (!match) throw new Error(`Cannot read the age "${text}"`)
155
+ return { ageValue: Number(match[1]), ageUnit: `${match[2]}s` }
156
+ }
157
+
158
+ /** Adds the sample pets (with placeholder pictures). Skips when real pets exist. Returns what it did. */
159
+ export async function addSamplePets(log: (line: string) => void = () => {}): Promise<number> {
160
+ let added = 0
161
+ const { db, t } = await getDatabase()
162
+
163
+ // Any pet that is not one of our samples (current or retired) means this is a real site: leave its
164
+ // pets alone.
165
+ const existing = await findSamplePets()
166
+ const [all] = await db.select({ n: count() }).from(t.pets)
167
+ if (all.n > existing.length) {
168
+ log('Real pets exist, skipping sample pets.')
169
+ return 0
170
+ }
171
+
172
+ // The pictures take the site's colours as they are now (the setup's theme step comes first).
173
+ const light = resolveTheme(await getSettings()).light
174
+ const colors = { primary: light['--primary'] ?? '#e8590c', bg: light['--bg'] ?? '#ffffff' }
175
+ const have = new Set(existing.map((d) => d.slug))
176
+
177
+ for (const [index, sample] of samples.entries()) {
178
+ if (have.has(slugify(sample.name))) continue
179
+
180
+ const buffer = await samplePicture(index, colors)
181
+ const media = await saveUpload({ data: buffer, alt: placeholderAlt(sample.name) })
182
+ try {
183
+ await savePet(null, {
184
+ name: sample.name,
185
+ status: sample.status ?? PetStatus.Available,
186
+ species: sample.species,
187
+ breed: sample.breed,
188
+ sex: sample.sex,
189
+ ...ageFrom(sample.ageDescription),
190
+ size: sample.size,
191
+ city: sample.city,
192
+ state: sample.state,
193
+ featured: sample.featured,
194
+ unlisted: sample.unlisted ?? false,
195
+ vaccinated: true,
196
+ neutered: sample.ageGroup !== 'baby',
197
+ photoIds: [media.id],
198
+ description: describe(sample.about),
199
+ ...extras[sample.name],
200
+ ...sample.extra,
201
+ })
202
+ added++
203
+ log(`Added sample pet ${sample.name}`)
204
+ } catch (error) {
205
+ // Don't leave an orphaned picture behind.
206
+ await removeUpload(media.id)
207
+ throw error
208
+ }
209
+ }
210
+
211
+ // Sample pets seeded before ages were birth dates get one now, so they age with the calendar.
212
+ const sampleIds = existing.map((pet) => pet.id)
213
+ const undated = sampleIds.length
214
+ ? (await db.select({ id: t.pets.id, slug: t.pets.slug, birthDate: t.pets.birthDate }).from(t.pets).where(inArray(t.pets.id, sampleIds))).filter((pet) => !pet.birthDate)
215
+ : []
216
+ for (const pet of undated) {
217
+ const sample = samples.find((s) => slugify(s.name) === pet.slug)
218
+ if (!sample) continue
219
+ await savePet(pet.id, ageFrom(sample.ageDescription))
220
+ log(`Gave ${sample.name} a birth date`)
221
+ }
222
+ return added
223
+ }
224
+
225
+ const ABOUT_SLUG = 'about'
226
+ const ABOUT_TITLE = 'About'
227
+
228
+ /**
229
+ * The sample site's settings (an updateSettings payload): `pnpm seed` fills them in while the
230
+ * settings are still the defaults, and the demo (src/server/demo-site.ts) on every fresh copy.
231
+ */
232
+ export function sampleSiteSettings() {
233
+ return {
234
+ siteName: 'Happy Tails Rescue',
235
+ tagline: 'Every pet deserves a loving home',
236
+ theme: 'sunrise',
237
+ // Placeholder number: replace it in Site settings.
238
+ whatsappNumber: '0120000000',
239
+ whatsappMessage: "Hi! I'm interested in adopting {pet}.",
240
+ address: '12 Jalan Contoh\n47400 Petaling Jaya\nSelangor',
241
+ openingHours: 'Sat & Sun, 10am - 5pm\nWeekdays by appointment',
242
+ nav: [
243
+ { label: 'Pets', href: '/pets' },
244
+ { label: 'About', href: `/${ABOUT_SLUG}` },
245
+ ],
246
+ footerText: 'Adopt, do not shop.',
247
+ }
248
+ }
249
+
250
+ /** The sample About page's layout. Its block ids are fixed (the page builder makes random ones). */
251
+ const ABOUT_LAYOUT = {
252
+ root: { props: {} },
253
+ zones: {},
254
+ content: [
255
+ { type: 'TextSection', props: { id: 'about-text', heading: 'About us', body: 'We are a small rescue helping cats, dogs and rabbits find loving homes.\n\nEvery pet is vaccinated, checked by a vet and matched with the right family.', align: 'left', background: 'none', spacing: 'md' } },
256
+ { type: 'Testimonials', props: { id: 'about-stories', heading: 'Happy tails', background: 'tint', items: [{ quote: 'Adopting Mochi was the best decision we ever made.', name: 'The Tan family', detail: 'Adopted Mochi' }] } },
257
+ { type: 'Faq', props: { id: 'about-faq', heading: 'Frequently asked questions', background: 'none', items: [{ question: 'How does adoption work?', answer: 'Message us on WhatsApp, meet the pet, and we will guide you through the next steps.' }, { question: 'Is there an adoption fee?', answer: 'We ask for a small contribution towards vet costs. Ask us for details.' }] } },
258
+ { type: 'ContactInfo', props: { id: 'about-contact', heading: 'Visit us', showAddress: true, showHours: true, showWhatsApp: true, mapEmbedUrl: '', background: 'none' } },
259
+ ],
260
+ }
261
+
262
+ /**
263
+ * Whether a layout is still the sample About page's: the same blocks with the same ids, in the same
264
+ * order, and the same heading and text in each (only the typed text: the save checks may tidy the
265
+ * choices if a block's options change).
266
+ */
267
+ const TYPED_TEXT = ['heading', 'body'] as const
268
+
269
+ function isSampleAboutLayout(data: unknown): boolean {
270
+ const content = (data as { content?: unknown } | null)?.content
271
+ if (!Array.isArray(content) || content.length !== ABOUT_LAYOUT.content.length) return false
272
+ return ABOUT_LAYOUT.content.every((block, index) => {
273
+ const stored = content[index] as { type?: unknown; props?: Record<string, unknown> } | null
274
+ if (stored?.type !== block.type || !stored.props) return false
275
+ const props: Record<string, unknown> = block.props
276
+ return stored.props.id === props.id && TYPED_TEXT.every((key) => stored.props![key] === props[key])
277
+ })
278
+ }
279
+
280
+ /**
281
+ * The sample About page while nobody has changed it: at /about, titled About, the sample layout both
282
+ * live and in the draft, no settings waiting to be published, and no version after the first (every
283
+ * edit, settings included, opens a new version). Anything else is the owner's page and stays.
284
+ */
285
+ async function findSampleAboutPage(): Promise<number | null> {
286
+ const { db, t } = await getDatabase()
287
+ const [page] = await db
288
+ .select({ id: t.pages.id, title: t.pages.title, draft: t.pages.puckDraft, published: t.pages.puckPublished, detailsDraft: t.pages.detailsDraft })
289
+ .from(t.pages)
290
+ .where(eq(t.pages.slug, ABOUT_SLUG))
291
+ .limit(1)
292
+ if (!page || page.title !== ABOUT_TITLE || page.detailsDraft != null) return null
293
+ if (!isSampleAboutLayout(page.published) || !isEqual(page.draft, page.published)) return null
294
+ const [versions] = await db.select({ newest: max(t.pageVersions.number) }).from(t.pageVersions).where(eq(t.pageVersions.pageId, page.id))
295
+ return (versions?.newest ?? 0) <= 1 ? page.id : null
296
+ }
297
+
298
+ /** Creates and publishes the sample About page, unless a page at /about exists. */
299
+ export async function addSampleAboutPage(log: (line: string) => void = () => {}): Promise<boolean> {
300
+ const { db, t } = await getDatabase()
301
+ const [existing] = await db.select({ n: count() }).from(t.pages).where(eq(t.pages.slug, ABOUT_SLUG))
302
+ if (existing.n > 0) {
303
+ log('An "about" page already exists, skipping.')
304
+ return false
305
+ }
306
+
307
+ const { id } = await savePageDetails(null, { title: ABOUT_TITLE, slug: ABOUT_SLUG })
308
+ await publishPage(id, ABOUT_LAYOUT)
309
+ log('Created the About page')
310
+ return true
311
+ }
312
+
313
+ /** Whether any sample pet (current or retired) is on the site. */
314
+ export async function hasSampleContent(): Promise<boolean> {
315
+ return (await findSamplePets()).length > 0
316
+ }
317
+
318
+ /**
319
+ * Takes the sample content out again: the sample pets, retired ones included, and their placeholder
320
+ * pictures (a picture something else now uses stays in the media library), and the sample About page
321
+ * while nobody has changed it. Pets and pages the owner made or edited are never touched (see
322
+ * findSamplePets and findSampleAboutPage). When a part cannot be removed, the rest is still removed and
323
+ * `left` names what stayed, so the caller can log what went and then say what is left
324
+ * (sampleContentLeftMessage).
325
+ */
326
+ export async function removeSampleContent(): Promise<{ pets: number; aboutPage: boolean; left: string[] }> {
327
+ const left: string[] = []
328
+ let removed = 0
329
+ let aboutPage = false
330
+ for (const pet of await findSamplePets()) {
331
+ try {
332
+ await deletePet(pet.id)
333
+ removed++
334
+ } catch (error) {
335
+ logError(error, `Could not remove the sample pet ${pet.id}`)
336
+ left.push(`the example pet ${pet.name}`)
337
+ continue
338
+ }
339
+ for (const mediaId of pet.photoIds) {
340
+ try {
341
+ await removeUpload(mediaId)
342
+ } catch (error) {
343
+ // Still in use somewhere else (the owner put it on a page): it stays, as it should.
344
+ if (isUserError(error)) continue
345
+ logError(error, `Could not remove the placeholder picture ${mediaId}`)
346
+ left.push(`the placeholder picture for ${pet.name}`)
347
+ }
348
+ }
349
+ }
350
+ const aboutId = await findSampleAboutPage()
351
+ if (aboutId !== null) {
352
+ try {
353
+ await archivePage(aboutId)
354
+ await deletePage(aboutId)
355
+ aboutPage = true
356
+ } catch (error) {
357
+ logError(error, 'Could not remove the sample About page')
358
+ left.push('the About page')
359
+ }
360
+ }
361
+ return { pets: removed, aboutPage, left }
362
+ }
363
+
364
+ /** The message for a removal that left something behind (see removeSampleContent). */
365
+ export function sampleContentLeftMessage(result: { pets: number; left: string[] }): string {
366
+ const what = `${result.left.join(', ')} could not be removed. Try again.`
367
+ return result.pets ? `Removed ${result.pets} example pet${result.pets === 1 ? '' : 's'}, but ${what}` : what.charAt(0).toUpperCase() + what.slice(1)
368
+ }
@@ -0,0 +1,43 @@
1
+ // Fills the folded search columns (pets.search_text, pets.location_search, media.search_text) for
2
+ // rows saved before they existed (migration 0011). Folding happens in JavaScript (foldText), so a
3
+ // migration cannot do it: this runs on server start and in `pnpm migrate`, and only touches rows
4
+ // whose column is still empty. New and edited rows get theirs on save.
5
+ import { foldText } from '@pet-adopt/plugin-sdk'
6
+ import { eq, isNull } from 'drizzle-orm'
7
+
8
+ import { getDatabase } from '@/db/client'
9
+
10
+ import { mediaSearchText } from './media'
11
+ import { petSearchText } from './pets'
12
+
13
+ const BATCH = 200
14
+
15
+ export async function backfillSearchText(): Promise<{ pets: number; media: number }> {
16
+ const { db, t } = await getDatabase()
17
+ let pets = 0
18
+ let media = 0
19
+ for (;;) {
20
+ const rows = await db
21
+ .select({ id: t.pets.id, name: t.pets.name, breed: t.pets.breed, location: t.pets.location })
22
+ .from(t.pets)
23
+ .where(isNull(t.pets.searchText))
24
+ .limit(BATCH)
25
+ if (!rows.length) break
26
+ for (const row of rows) {
27
+ await db
28
+ .update(t.pets)
29
+ .set({ searchText: petSearchText(row), locationSearch: foldText(row.location) || null })
30
+ .where(eq(t.pets.id, row.id))
31
+ pets++
32
+ }
33
+ }
34
+ for (;;) {
35
+ const rows = await db.select({ id: t.media.id, name: t.media.name, alt: t.media.alt }).from(t.media).where(isNull(t.media.searchText)).limit(BATCH)
36
+ if (!rows.length) break
37
+ for (const row of rows) {
38
+ await db.update(t.media).set({ searchText: mediaSearchText(row) }).where(eq(t.media.id, row.id))
39
+ media++
40
+ }
41
+ }
42
+ return { pets, media }
43
+ }
@@ -0,0 +1,38 @@
1
+ // Small secrets the app must read back (the SMTP password), encrypted at rest. AES-256-GCM with a
2
+ // key derived from BETTER_AUTH_SECRET by HKDF-SHA256, so the database alone (a backup, a leaked
3
+ // dump) does not give the password away. Stored as `v1.<iv>.<tag>.<ciphertext>` (base64url).
4
+ //
5
+ // Changing BETTER_AUTH_SECRET makes stored values unreadable: `open` then returns null and the
6
+ // screen asks for the password again. Nothing here is for passwords people sign in with (those are
7
+ // hashed by Better Auth).
8
+ import { createCipheriv, createDecipheriv, hkdfSync, randomBytes } from 'node:crypto'
9
+
10
+ import { authSecret } from './auth'
11
+
12
+ const VERSION = 'v1'
13
+
14
+ function keyFor(purpose: string): Buffer {
15
+ return Buffer.from(hkdfSync('sha256', authSecret(), 'pet-adopt secret-box', `${VERSION}:${purpose}`, 32))
16
+ }
17
+
18
+ /** Encrypts `plain` for one `purpose` (a value sealed for one purpose cannot be opened as another). */
19
+ export function seal(plain: string, purpose: string): string {
20
+ const iv = randomBytes(12)
21
+ const cipher = createCipheriv('aes-256-gcm', keyFor(purpose), iv)
22
+ const data = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()])
23
+ return [VERSION, iv.toString('base64url'), cipher.getAuthTag().toString('base64url'), data.toString('base64url')].join('.')
24
+ }
25
+
26
+ /** The plain text, or null when the value is damaged or was sealed with another secret or purpose. */
27
+ export function open(sealed: string | null | undefined, purpose: string): string | null {
28
+ if (!sealed) return null
29
+ const [version, iv, tag, data] = sealed.split('.')
30
+ if (version !== VERSION || !iv || !tag || data === undefined) return null
31
+ try {
32
+ const decipher = createDecipheriv('aes-256-gcm', keyFor(purpose), Buffer.from(iv, 'base64url'))
33
+ decipher.setAuthTag(Buffer.from(tag, 'base64url'))
34
+ return Buffer.concat([decipher.update(Buffer.from(data, 'base64url')), decipher.final()]).toString('utf8')
35
+ } catch {
36
+ return null
37
+ }
38
+ }
@@ -0,0 +1,154 @@
1
+ // Who is signed in. Every server action starts with requirePermission(...), or requireUser() for a
2
+ // person's own account. What each role may do is the table in the plugin SDK (`can`).
3
+ import { asRole, can, ROLE_INFO, type Permission } from '@pet-adopt/plugin-sdk'
4
+ import { eq } from 'drizzle-orm'
5
+ import { cookies, headers } from 'next/headers'
6
+ import { connection } from 'next/server'
7
+ import { cache } from 'react'
8
+
9
+ import { getDatabase } from '@/db/client'
10
+ import { DEMO_ACCOUNT, DEMO_COOKIE, isDemo } from '@/lib/demo'
11
+
12
+ import { getAuth } from './auth'
13
+ import { UserError } from './result'
14
+ import { needsTwoFactorSetup } from './two-factor'
15
+ import type { SessionUser } from './types'
16
+
17
+ /** The signed-in person, or null. Looked up once per request. */
18
+ export const getSessionUser = cache(async (): Promise<SessionUser | null> => {
19
+ // Read the request FIRST, before the database or the clock. A prerender (`next build`, and the
20
+ // prefetches Next makes while the site runs) stops at these two lines, so nothing below runs
21
+ // without a visitor: no database at build time (a missing SQLite file would fail it with
22
+ // SQLITE_CANTOPEN), and the clock reads that follow (session expiry, getAuth's recheck) count as
23
+ // request time. headers() alone is not enough under Cache Components: Next still reports a clock
24
+ // read after it. connection() resolves at once in server actions and route handlers.
25
+ const requestHeaders = await headers()
26
+ await connection()
27
+ // The public demo (src/lib/demo.ts) has no Better Auth sessions at all: a visitor who pressed
28
+ // "Open the admin" carries the demo cookie and is the shared demo account of whichever server
29
+ // instance answers (each has its own copy, so the cookie cannot name an account id). No cookie
30
+ // means signed out. Off the demo the cookie means nothing and is never read.
31
+ if (isDemo()) return (await cookies()).get(DEMO_COOKIE)?.value === DEMO_COOKIE_VALUE ? demoAccount() : null
32
+ const auth = await getAuth()
33
+ const session = await auth.api.getSession({ headers: requestHeaders })
34
+ if (!session?.user) return null
35
+ const signInMethod = (session.session as { signInMethod?: string | null }).signInMethod || 'password'
36
+ const { id, email, name, role, twoFactorEnabled, archivedAt, image, emailVerified } = session.user as {
37
+ id: string
38
+ emailVerified?: boolean | null
39
+ image?: string | null
40
+ email: string
41
+ name: string
42
+ role?: string | null
43
+ twoFactorEnabled?: boolean | null
44
+ archivedAt?: Date | string | null
45
+ }
46
+ // Archiving deletes the account's sessions; this also covers one made at that same moment.
47
+ if (archivedAt) return null
48
+ return { id, email, name, role: asRole(role), twoFactorEnabled: Boolean(twoFactorEnabled), signInMethod, image: image ?? null, emailVerified: emailVerified !== false }
49
+ })
50
+
51
+ // --- The public demo (src/lib/demo.ts) -------------------------------------------------------
52
+ // One shared account that every visitor opens with one click (enterDemoAction in actions/demo.ts).
53
+ // The cookie carries nothing worth forging (anyone gets it with that click), so it is not sealed;
54
+ // what keeps it harmless is that it is only honoured while the demo is switched on, and the demo
55
+ // refuses to start over a real database or bucket (demoProblem).
56
+
57
+ /** How a demo visitor "signed in" (SessionUser.signInMethod): neither a password nor a provider. */
58
+ export const DEMO_SIGN_IN_METHOD = 'demo'
59
+ const DEMO_COOKIE_VALUE = '1'
60
+ /** A day, then the visitor presses the button again. */
61
+ const DEMO_COOKIE_SECONDS = 24 * 60 * 60
62
+
63
+ function demoCookieOptions(maxAge: number) {
64
+ return { httpOnly: true, sameSite: 'lax' as const, secure: process.env.NODE_ENV === 'production', path: '/', maxAge }
65
+ }
66
+
67
+ /**
68
+ * The demo's shared account in this instance's copy, as a signed-in person, or null: when the demo
69
+ * is off (so this can never open a real site, whoever calls it), or the account is missing or
70
+ * archived. Role, picture and the rest come from the row, like any account.
71
+ */
72
+ export async function demoAccount(): Promise<SessionUser | null> {
73
+ if (!isDemo()) return null
74
+ const { db, t } = await getDatabase()
75
+ const [row] = await db
76
+ .select({
77
+ id: t.users.id,
78
+ email: t.users.email,
79
+ name: t.users.name,
80
+ role: t.users.role,
81
+ twoFactorEnabled: t.users.twoFactorEnabled,
82
+ archivedAt: t.users.archivedAt,
83
+ image: t.users.image,
84
+ emailVerified: t.users.emailVerified,
85
+ })
86
+ .from(t.users)
87
+ .where(eq(t.users.email, DEMO_ACCOUNT.email))
88
+ .limit(1)
89
+ if (!row || row.archivedAt) return null
90
+ return {
91
+ id: row.id,
92
+ email: row.email,
93
+ name: row.name,
94
+ role: asRole(row.role),
95
+ twoFactorEnabled: Boolean(row.twoFactorEnabled),
96
+ signInMethod: DEMO_SIGN_IN_METHOD,
97
+ image: row.image ?? null,
98
+ emailVerified: row.emailVerified !== false,
99
+ }
100
+ }
101
+
102
+ /** Whether this request already carries the demo cookie (only meaningful while the demo is on). */
103
+ export async function hasDemoCookie(): Promise<boolean> {
104
+ return isDemo() && (await cookies()).get(DEMO_COOKIE)?.value === DEMO_COOKIE_VALUE
105
+ }
106
+
107
+ /** Gives this browser the demo cookie: signed in as the demo account on every instance. Demo only. */
108
+ export async function setDemoCookie(): Promise<void> {
109
+ if (!isDemo()) throw new UserError('This site is not the demo.')
110
+ ;(await cookies()).set(DEMO_COOKIE, DEMO_COOKIE_VALUE, demoCookieOptions(DEMO_COOKIE_SECONDS))
111
+ }
112
+
113
+ /** Removes the demo cookie (signing out of the demo). Same attributes, so the browser replaces it. */
114
+ export async function clearDemoCookie(): Promise<void> {
115
+ ;(await cookies()).set(DEMO_COOKIE, '', demoCookieOptions(0))
116
+ }
117
+
118
+ /**
119
+ * Anyone signed in, whatever their role. Only for a person's own account (name, password,
120
+ * two-factor), so it works before someone who must set up two-factor has done so.
121
+ */
122
+ export async function requireUser(): Promise<SessionUser> {
123
+ const user = await getSessionUser()
124
+ if (!user) throw new UserError('You need to be signed in.')
125
+ return user
126
+ }
127
+
128
+ /**
129
+ * The signed-in person, if their role has `permission`; a UserError that says why otherwise.
130
+ *
131
+ * @param opts.unconfirmed Lets an account whose email is not confirmed through: only for fixing how
132
+ * the site sends email (saving the SMTP settings, a test email). Otherwise a wrong SMTP setting
133
+ * would lock everyone out: the rule is on, and the confirmation email cannot arrive.
134
+ */
135
+ export async function requirePermission(permission: Permission, opts: { unconfirmed?: boolean } = {}): Promise<SessionUser> {
136
+ const user = await requireUser()
137
+ // Their role must use two-factor and they have not set it up: nothing else until they do.
138
+ if (await needsTwoFactorSetup(user)) throw new UserError('Set up two-factor sign-in first (your role requires it).')
139
+ if (can(user.role, permission)) {
140
+ // Every account confirms its email before it changes anything (viewing is fine).
141
+ // Loaded lazily: email-change reaches the plugin registry, whose host imports this file.
142
+ const changes = permission.endsWith(':edit') || permission.endsWith(':export')
143
+ if (changes && !opts.unconfirmed && (await (await import('./email-change')).needsEmailConfirmation(user))) {
144
+ throw new UserError('Confirm your email first: use “Send confirmation link” at the top of the admin.')
145
+ }
146
+ return user
147
+ }
148
+ const role = ROLE_INFO[user.role].label
149
+ if (permission === 'personalData:export' || permission === 'activity:export') throw new UserError(`Your role (${role}) cannot download this.`)
150
+ const [area] = permission.split(':') as [string]
151
+ // Say "view only" when they can see it but not do this, so the message matches the screen.
152
+ const viewOnly = permission !== `${area}:view` && can(user.role, `${area}:view` as Permission)
153
+ throw new UserError(viewOnly ? `Your role (${role}) can view this but not change it.` : `Your role (${role}) does not have access to this.`)
154
+ }