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,405 @@
1
+ // Requests against a RUNNING production build of the site, for what only a real server shows: real
2
+ // pages answer 200 with CDN headers, unknown addresses a real 404 on the first request, and the
3
+ // routes that work per request (health, robots.txt, sitemap.xml, the admin) answer.
4
+ //
5
+ // Why: the pet and page routes prerender one real slug at build time (generateStaticParams), and a
6
+ // build with no database prerenders none, only the not-found path. A mistake on the found path (an
7
+ // uncached read, a clock read outside a cache, a block loader that reads the request) then passes
8
+ // the build and answers 500 at run time. So this script asks for a pet and a page the build did not
9
+ // prerender, when there is one: the run-time render is what gets checked.
10
+ //
11
+ // Needs: a production server already running (`next build`, then `next start`; not `next dev`,
12
+ // whose status codes and headers differ) and the same DATABASE_URL as that server. It reads one
13
+ // listed pet that is not adopted and one live page of the owners' own (not the homepage, the Pets
14
+ // page or the Pet page template) through the data layer, as sitemap.xml lists them. A database
15
+ // that check:backend filled has both; otherwise run `pnpm seed`, or add them in the admin.
16
+ //
17
+ // pnpm build
18
+ // pnpm start (in another terminal; PORT=3100 for another port)
19
+ // pnpm check:routes (BASE_URL=http://localhost:3000 by default)
20
+ //
21
+ // In demo mode (PET_ADOPT_DEMO=1, src/lib/demo.ts) run it with PET_ADOPT_DEMO=1 and no DATABASE_URL
22
+ // or S3_* settings instead: it reads its own throwaway copy of the same sample content.
23
+ //
24
+ // With SEED_ADMIN_EMAIL and SEED_ADMIN_PASSWORD set to an admin of that site (as CI seeds one), it
25
+ // also signs in and opens every admin screen and builder: a screen that fails on the server only in
26
+ // a production build passes the typecheck and the build. Without them, and in demo mode, that part
27
+ // is skipped and says so. The account must not have two-factor sign-in, and each run is one sign-in
28
+ // from this machine: many runs in a row can meet the limit of 30 per address in 15 minutes.
29
+ //
30
+ // The two unknown /media/<name>.png addresses ask the storage for the file, so the server needs
31
+ // working S3_* settings (or demo mode, which keeps pictures in memory).
32
+ //
33
+ // One line per check; exits 1 when any fails. GET requests and database reads only, apart from that
34
+ // one sign-in (a session, and its entries in the activity log) and the sign-out that ends it.
35
+ import { randomBytes } from 'node:crypto'
36
+
37
+ import config from '../pet-adopt.config'
38
+ import { closeDatabase, getDatabase } from '../src/db/client'
39
+ import { isDemo } from '../src/lib/demo'
40
+ import { anyPublicPageSlug, anyPublicPetSlug, sitemapEntries } from '../src/server/sitemap'
41
+
42
+ const BASE_URL = (process.env.BASE_URL || 'http://localhost:3000').replace(/\/+$/, '')
43
+ // Not a link-preview bot: those always get a page drawn per request, without CDN headers.
44
+ const USER_AGENT = 'Mozilla/5.0 (pet-adopt check-routes)'
45
+
46
+ let failures = 0
47
+ async function check(name: string, fn: () => Promise<string | void>) {
48
+ try {
49
+ const detail = await fn()
50
+ console.log(`PASS ${name}${detail ? ` (${detail})` : ''}`)
51
+ } catch (error) {
52
+ failures++
53
+ console.log(`FAIL ${name} (${error instanceof Error ? error.message : String(error)})`)
54
+ }
55
+ }
56
+ const ok = (cond: unknown, msg: string) => {
57
+ if (!cond) throw new Error(msg)
58
+ }
59
+
60
+ type Answer = { status: number; headers: Headers; body: string }
61
+
62
+ async function get(path: string, cookie = ''): Promise<Answer> {
63
+ const response = await fetch(`${BASE_URL}${path}`, {
64
+ redirect: 'manual',
65
+ headers: { 'user-agent': USER_AGENT, accept: 'text/html,application/xhtml+xml,*/*;q=0.8', ...(cookie ? { cookie } : {}) },
66
+ signal: AbortSignal.timeout(60_000),
67
+ })
68
+ return { status: response.status, headers: response.headers, body: await response.text() }
69
+ }
70
+
71
+ /** The status and the headers worth seeing in a line. */
72
+ function describe(answer: Answer): string {
73
+ const parts = [`${answer.status}`, `cache-control: ${answer.headers.get('cache-control') ?? 'none'}`]
74
+ const cache = answer.headers.get('x-nextjs-cache')
75
+ if (cache) parts.push(`x-nextjs-cache: ${cache}`)
76
+ return parts.join(', ')
77
+ }
78
+
79
+ const unescapeHtml = (text: string) => text.replace(/&amp;/g, '&').replace(/&quot;/g, '"').replace(/&#x27;|&#39;/g, "'")
80
+
81
+ /**
82
+ * Where a redirect sends the browser, and how: the Location of a 30x answer, or, when the page had
83
+ * started streaming before the redirect, the target Next writes into the 200 page (a refresh
84
+ * <meta id="__next-page-redirect">, and the NEXT_REDIRECT digest in the page's payload).
85
+ */
86
+ function redirectOf(answer: Answer): { how: string; to: string } | null {
87
+ const location = answer.headers.get('location')
88
+ if (answer.status >= 300 && answer.status < 400 && location) {
89
+ const url = new URL(location, BASE_URL)
90
+ return { how: `a real ${answer.status} with Location`, to: url.pathname + url.search }
91
+ }
92
+ const meta = /<meta\b[^>]*\bid="__next-page-redirect"[^>]*>/i.exec(answer.body)?.[0]
93
+ const fromMeta = meta ? /\bcontent="\d+;url=([^"]*)"/i.exec(meta)?.[1] : undefined
94
+ if (fromMeta) return { how: `a ${answer.status} whose page redirects (refresh <meta>)`, to: unescapeHtml(fromMeta) }
95
+ const digest = /NEXT_REDIRECT;(?:replace|push);([^;"\\]+);30[78];/.exec(answer.body)?.[1]
96
+ if (digest) return { how: `a ${answer.status} whose page redirects (NEXT_REDIRECT in the payload)`, to: digest }
97
+ return null
98
+ }
99
+
100
+ /** The page's title: the last <title> in the answer (Next may send it after the page has started). */
101
+ function titleOf(answer: Answer): string | null {
102
+ const titles = [...answer.body.matchAll(/<title[^>]*>([^<]*)<\/title>/g)]
103
+ return titles.length ? unescapeHtml(titles[titles.length - 1][1]) : null
104
+ }
105
+
106
+ /** Whether the answer is a "not found": a real 404, or the 200 a signed-in page answers with Next's 404 inside it (the page had started streaming). */
107
+ const isNotFound = (answer: Answer) => answer.status === 404 || /NEXT_HTTP_ERROR_FALLBACK;404/.test(answer.body)
108
+
109
+ /**
110
+ * Whether part of the page failed on the server: React then tells the browser to draw that part's
111
+ * error boundary, with the error's reference number (a redirect or a "not found" carries words).
112
+ */
113
+ const hasServerError = (answer: Answer) => /\$RX\("[^"]+","\d+"/.test(answer.body)
114
+
115
+ /** One line about an answer to a page request, for a failure message. */
116
+ function describePage(answer: Answer): string {
117
+ const redirect = redirectOf(answer)
118
+ return `${answer.status}, title ${JSON.stringify(titleOf(answer))}${redirect ? `, redirects to ${redirect.to}` : ''}${isNotFound(answer) ? ', not found' : ''}${hasServerError(answer) ? ', a part of it failed on the server (see the server log)' : ''}`
119
+ }
120
+
121
+ // --- What to ask for, from the same database as the server --------------------------------
122
+
123
+ const paths = (await sitemapEntries()).map((entry) => new URL(entry.url).pathname)
124
+ const petSlugs = paths.filter((path) => path.startsWith('/pets/')).map((path) => decodeURIComponent(path.slice('/pets/'.length)))
125
+ const pageSlugs = paths.filter((path) => path !== '/' && path !== '/pets' && !path.startsWith('/pets/')).map((path) => decodeURIComponent(path.slice(1)))
126
+ // The slugs the build prerendered (generateStaticParams): another one is drawn at run time.
127
+ const [builtPet, builtPage] = await Promise.all([anyPublicPetSlug(), anyPublicPageSlug()])
128
+ // The signed-in part (see the header), and one real id per kind of screen for its `[id]` addresses.
129
+ // A kind with no row (a site with no saved theme, say) is only asked for with an id nothing has.
130
+ const email = process.env.SEED_ADMIN_EMAIL?.trim()
131
+ const password = process.env.SEED_ADMIN_PASSWORD
132
+ const signsIn = !isDemo() && Boolean(email && password)
133
+ const ids: { pet: number | null; page: number | null; media: number | null; theme: number | null } = { pet: null, page: null, media: null, theme: null }
134
+ if (signsIn) {
135
+ const { db, t } = await getDatabase()
136
+ const firstId = async (rows: Promise<{ id: number }[]>) => (await rows)[0]?.id ?? null
137
+ ids.pet = await firstId(db.select({ id: t.pets.id }).from(t.pets).limit(1))
138
+ ids.page = await firstId(db.select({ id: t.pages.id }).from(t.pages).limit(1))
139
+ ids.media = await firstId(db.select({ id: t.media.id }).from(t.media).limit(1))
140
+ ids.theme = await firstId(db.select({ id: t.themes.id }).from(t.themes).limit(1))
141
+ }
142
+ await closeDatabase()
143
+ const pet = petSlugs.find((slug) => slug !== builtPet) ?? petSlugs[0] ?? null
144
+ const page = pageSlugs.find((slug) => slug !== builtPage) ?? pageSlugs[0] ?? null
145
+ const prerendered = (slug: string | null, built: string | null) => (slug !== null && slug === built ? ', the one the build prerendered (the only one there is)' : '')
146
+
147
+ console.log(`Checking ${BASE_URL}: pet "${pet ?? 'none'}"${prerendered(pet, builtPet)}, page "${page ?? 'none'}"${prerendered(page, builtPage)}`)
148
+
149
+ try {
150
+ await get('/health')
151
+ } catch (error) {
152
+ console.log(`FAIL no server answers at ${BASE_URL} (${error instanceof Error ? error.message : String(error)}). Start it first: pnpm start`)
153
+ process.exit(1)
154
+ }
155
+
156
+ // --- Found: 200 with CDN headers on the first request ----------------------------------------
157
+
158
+ await check('a pet page answers 200 with s-maxage on its first request', async () => {
159
+ ok(pet, 'the database has no listed pet that is not adopted: add one (pnpm seed, or the admin) and run this again')
160
+ const answer = await get(`/pets/${encodeURIComponent(pet!)}`)
161
+ ok(answer.status === 200 && /s-maxage=/.test(answer.headers.get('cache-control') ?? ''), `/pets/${pet}: ${describe(answer)}`)
162
+ return `/pets/${pet}: ${describe(answer)}`
163
+ })
164
+
165
+ await check('a page of the owners\' own answers 200 with s-maxage on its first request', async () => {
166
+ ok(page, 'the database has no live page besides the homepage, the Pets page and the Pet page template: publish one (pnpm seed adds an About page) and run this again')
167
+ const answer = await get(`/${encodeURIComponent(page!)}`)
168
+ ok(answer.status === 200 && /s-maxage=/.test(answer.headers.get('cache-control') ?? ''), `/${page}: ${describe(answer)}`)
169
+ return `/${page}: ${describe(answer)}`
170
+ })
171
+
172
+ await check('the homepage answers 200 with s-maxage', async () => {
173
+ const answer = await get('/')
174
+ ok(answer.status === 200 && /s-maxage=/.test(answer.headers.get('cache-control') ?? ''), describe(answer))
175
+ return describe(answer)
176
+ })
177
+
178
+ await check('the Pets page (/pets) answers 200', async () => {
179
+ const answer = await get('/pets')
180
+ ok(answer.status === 200, describe(answer))
181
+ return describe(answer)
182
+ })
183
+
184
+ // --- Not found: a real 404 on the first request ------------------------------------------------
185
+
186
+ const unknown = `check-routes-${randomBytes(4).toString('hex')}`
187
+ for (const path of ['/pets/__none__', '/__none__', '/pet-page', `/pets/${unknown}`, `/${unknown}`]) {
188
+ await check(`${path} answers 404`, async () => {
189
+ const answer = await get(path)
190
+ ok(answer.status === 404, describe(answer))
191
+ return describe(answer)
192
+ })
193
+ }
194
+
195
+ await check('/home redirects to /', async () => {
196
+ const answer = await get('/home')
197
+ const redirect = redirectOf(answer)
198
+ ok(redirect?.to === '/', `${describe(answer)}, redirect: ${redirect ? `${redirect.how} to ${redirect.to}` : 'none found'}`)
199
+ return redirect!.how
200
+ })
201
+
202
+ // --- Per-request routes ----------------------------------------------------------------------------
203
+
204
+ await check('/health answers 200 with {"ok":true}', async () => {
205
+ const answer = await get('/health')
206
+ let body: unknown = null
207
+ try {
208
+ body = JSON.parse(answer.body)
209
+ } catch {
210
+ // Not JSON: reported below.
211
+ }
212
+ ok(answer.status === 200 && (body as { ok?: unknown } | null)?.ok === true, `${describe(answer)}, body: ${answer.body.slice(0, 100)}`)
213
+ return describe(answer)
214
+ })
215
+
216
+ let indexing = true
217
+ await check('/robots.txt answers 200', async () => {
218
+ const answer = await get('/robots.txt')
219
+ ok(answer.status === 200, describe(answer))
220
+ // A preview or SEARCH_INDEXING=off disallows everything and empties the sitemap (src/lib/seo.ts).
221
+ indexing = /^allow:\s*\/\s*$/im.test(answer.body)
222
+ // Whatever else it says, the signed-in areas and the machine routes are never offered to crawlers.
223
+ if (indexing) for (const path of ['/admin', '/edit', '/api', '/setup']) ok(new RegExp(`^disallow:\\s*${path}\\s*$`, 'im').test(answer.body), `no "Disallow: ${path}" line`)
224
+ return `${describe(answer)}, search indexing ${indexing ? 'allowed' : 'off on this server'}`
225
+ })
226
+
227
+ await check('/sitemap.xml answers 200 and lists the pet', async () => {
228
+ const answer = await get('/sitemap.xml')
229
+ ok(answer.status === 200, describe(answer))
230
+ if (!indexing) return `${describe(answer)}; empty by design while search indexing is off, so the pet is not looked for`
231
+ ok(pet, 'no pet to look for (see the pet page check)')
232
+ ok(answer.body.includes(`/pets/${encodeURIComponent(pet!)}</loc>`), `/pets/${pet} is not in it`)
233
+ return describe(answer)
234
+ })
235
+
236
+ await check('/admin signed out leads to /admin/login', async () => {
237
+ const answer = await get('/admin')
238
+ const redirect = redirectOf(answer)
239
+ ok((answer.status === 200 || answer.status === 307) && redirect?.to.startsWith('/admin/login'), `${describe(answer)}, redirect: ${redirect ? `${redirect.how} to ${redirect.to}` : 'none found'}`)
240
+ return `${redirect!.how} to ${redirect!.to}`
241
+ })
242
+
243
+ // --- Uploads ---------------------------------------------------------------------------------------
244
+
245
+ for (const path of ['/media/email', '/media/email/a/b', `/media/email/${unknown}.png`, `/media/${unknown}.png`]) {
246
+ await check(`${path} answers 404, cached for a minute`, async () => {
247
+ const answer = await get(path)
248
+ ok(answer.status === 404 && answer.headers.get('cache-control') === 'public, max-age=60', describe(answer))
249
+ return describe(answer)
250
+ })
251
+ }
252
+
253
+ // --- Sign-in pages ----------------------------------------------------------------------------------
254
+
255
+ // The titles and the no-referrer rule (the three pages that take a one-time link in their address).
256
+ const SIGN_IN_PAGES = [
257
+ { path: '/admin/login', title: 'Sign in', noReferrer: false },
258
+ { path: '/admin/invite', title: 'Accept invite | Admin', noReferrer: true },
259
+ { path: '/admin/reset-password', title: 'Reset password | Admin', noReferrer: true },
260
+ { path: '/admin/confirm-email', title: 'Confirm your email | Admin', noReferrer: true },
261
+ ]
262
+ for (const page of SIGN_IN_PAGES) {
263
+ await check(`${page.path} answers 200, titled "${page.title}", noindex${page.noReferrer ? ', no-referrer' : ''}`, async () => {
264
+ const answer = await get(page.path)
265
+ ok(answer.status === 200 && titleOf(answer) === page.title, describePage(answer))
266
+ ok(/<meta name="robots" content="noindex/.test(answer.body), 'no noindex robots <meta>')
267
+ if (page.noReferrer) ok(/<meta name="referrer" content="no-referrer"/.test(answer.body), 'no no-referrer <meta>')
268
+ return describe(answer)
269
+ })
270
+ }
271
+
272
+ await check('/setup signed out leads to the sign-in page and back, or shows the setup of a site with no account', async () => {
273
+ const answer = await get('/setup')
274
+ const redirect = redirectOf(answer)
275
+ ok(answer.status === 200 && titleOf(answer) === 'Set up your site | Setup' && (!redirect || redirect.to === '/admin/login?redirect=%2Fsetup'), describePage(answer))
276
+ return redirect ? `${redirect.how} to ${redirect.to}` : 'the setup page'
277
+ })
278
+
279
+ // --- Signed in ---------------------------------------------------------------------------------------
280
+
281
+ const NO_SUCH_ID = '999999999'
282
+ // Every admin screen and its title ("<title> | <site name> admin"). A screen with an id is asked for
283
+ // when the site has such a row.
284
+ const ADMIN_SCREENS: { path: string; title: string }[] = [
285
+ { path: '/admin', title: 'Dashboard' },
286
+ { path: '/admin/account', title: 'Account' },
287
+ { path: '/admin/activity', title: 'Activity' },
288
+ { path: '/admin/media', title: 'Media' },
289
+ ...(ids.media !== null ? [{ path: `/admin/media/${ids.media}`, title: 'Image' }] : []),
290
+ { path: '/admin/pages', title: 'Pages' },
291
+ { path: '/admin/pages/new', title: 'New page' },
292
+ ...(ids.page !== null ? [{ path: `/admin/pages/${ids.page}`, title: 'Page settings' }] : []),
293
+ { path: '/admin/pets', title: 'Pets' },
294
+ { path: '/admin/pets/new', title: 'Add pet' },
295
+ ...(ids.pet !== null ? [{ path: `/admin/pets/${ids.pet}`, title: 'Edit pet' }] : []),
296
+ { path: '/admin/plugins', title: 'Plugins' },
297
+ { path: '/admin/settings', title: 'Site settings' },
298
+ { path: '/admin/theme', title: 'Theme' },
299
+ ...(ids.theme !== null ? [{ path: `/admin/theme/${ids.theme}`, title: 'Edit theme' }] : []),
300
+ { path: '/admin/users', title: 'Users' },
301
+ { path: '/admin/email', title: 'Email' },
302
+ { path: '/admin/email/templates', title: 'Email templates' },
303
+ { path: '/admin/authentication', title: 'Two-factor' },
304
+ { path: '/admin/authentication/providers', title: 'Sign-in providers' },
305
+ { path: '/admin/authentication/archived', title: 'Archived accounts' },
306
+ ]
307
+ // Each plugin's own page (its home screen, or the built-in overview), whatever it is titled.
308
+ const PLUGIN_SCREENS = (config.plugins ?? []).map((plugin) => `/admin/plugins/${plugin.name}`)
309
+ // The builders: a page's (every site has the homepage), and the site's own password-reset email.
310
+ const BUILDERS = [
311
+ { path: `/edit/${ids.page ?? 1}`, title: 'Page builder' },
312
+ { path: `/edit/${ids.page ?? 1}/preview`, title: 'Preview' },
313
+ { path: '/edit/email/password-reset', title: 'Email builder' },
314
+ { path: '/edit/theme-preview', title: 'Theme preview' },
315
+ ]
316
+
317
+ if (!signsIn) {
318
+ console.log(`SKIP the signed-in checks (${isDemo() ? 'demo mode has no password sign-in' : 'set SEED_ADMIN_EMAIL and SEED_ADMIN_PASSWORD to an admin of this site to run them'})`)
319
+ } else {
320
+ let cookie = ''
321
+ await check('the seeded admin signs in over HTTP', async () => {
322
+ const response = await fetch(`${BASE_URL}/api/auth/sign-in/email`, {
323
+ method: 'POST',
324
+ headers: { 'content-type': 'application/json', origin: BASE_URL, 'user-agent': USER_AGENT },
325
+ body: JSON.stringify({ email, password }),
326
+ signal: AbortSignal.timeout(60_000),
327
+ })
328
+ const body = await response.text()
329
+ cookie = response.headers
330
+ .getSetCookie()
331
+ .map((line) => line.split(';')[0])
332
+ .join('; ')
333
+ ok(response.status === 200 && cookie, `${response.status}: ${body.slice(0, 200)}`)
334
+ ok(!/twoFactorRedirect/.test(body), 'this account has two-factor sign-in, which cannot be finished over HTTP: use an admin without it')
335
+ })
336
+
337
+ if (cookie) {
338
+ await check(`signed in, the ${ADMIN_SCREENS.length + PLUGIN_SCREENS.length} admin screens open with their title`, async () => {
339
+ const wrong: string[] = []
340
+ for (const screen of [...ADMIN_SCREENS, ...PLUGIN_SCREENS.map((path) => ({ path, title: null }))]) {
341
+ const answer = await get(screen.path, cookie)
342
+ const redirect = redirectOf(answer)
343
+ const title = titleOf(answer)
344
+ if (
345
+ answer.status !== 200 ||
346
+ isNotFound(answer) ||
347
+ hasServerError(answer) ||
348
+ // Only the dashboard sends anyone on: an admin of a site whose guided setup is not finished.
349
+ (redirect && !(screen.path === '/admin' && redirect.to === '/setup')) ||
350
+ // "<screen> | <site name> admin"; a plugin's page names itself.
351
+ !(screen.title !== null ? title?.startsWith(`${screen.title} | `) : title && !title.startsWith('Not found')) ||
352
+ !title?.endsWith(' admin')
353
+ ) {
354
+ wrong.push(`${screen.path}: ${describePage(answer)}`)
355
+ }
356
+ }
357
+ ok(!wrong.length, wrong.join('; '))
358
+ })
359
+
360
+ await check('signed in, the older Email addresses under Site settings send people on', async () => {
361
+ const wrong: string[] = []
362
+ for (const [path, to] of [['/admin/settings/email', '/admin/email'], ['/admin/settings/templates', '/admin/email/templates']]) {
363
+ const answer = await get(path, cookie)
364
+ if (redirectOf(answer)?.to !== to) wrong.push(`${path}: ${describePage(answer)}`)
365
+ }
366
+ ok(!wrong.length, wrong.join('; '))
367
+ })
368
+
369
+ await check(`signed in, the ${BUILDERS.length} builder addresses open with their title, noindex`, async () => {
370
+ const wrong: string[] = []
371
+ for (const builder of BUILDERS) {
372
+ const answer = await get(builder.path, cookie)
373
+ if (answer.status !== 200 || isNotFound(answer) || hasServerError(answer) || redirectOf(answer) || titleOf(answer) !== builder.title || !/<meta name="robots" content="noindex/.test(answer.body)) {
374
+ wrong.push(`${builder.path}: ${describePage(answer)}`)
375
+ }
376
+ }
377
+ ok(!wrong.length, wrong.join('; '))
378
+ })
379
+
380
+ await check('signed in, an unknown id or plugin under /admin is "not found"', async () => {
381
+ const wrong: string[] = []
382
+ const unknownIds = ['pets', 'pages', 'media', 'theme'].flatMap((kind) => [`/admin/${kind}/${NO_SUCH_ID}`, `/admin/${kind}/abc`])
383
+ for (const path of [...unknownIds, `/admin/plugins/${unknown}`, ...PLUGIN_SCREENS.map((screen) => `${screen}/${unknown}`)]) {
384
+ const answer = await get(path, cookie)
385
+ if (!isNotFound(answer) || redirectOf(answer)) wrong.push(`${path}: ${describePage(answer)}`)
386
+ }
387
+ ok(!wrong.length, wrong.join('; '))
388
+ })
389
+
390
+ await check('signed in, a page or an email template that does not exist is "not found" in the builders', async () => {
391
+ const wrong: string[] = []
392
+ for (const path of [`/edit/${NO_SUCH_ID}`, `/edit/${NO_SUCH_ID}/preview`, `/edit/email/${NO_SUCH_ID}`]) {
393
+ const answer = await get(path, cookie)
394
+ if (!isNotFound(answer) || redirectOf(answer)) wrong.push(`${path}: ${describePage(answer)}`)
395
+ }
396
+ ok(!wrong.length, wrong.join('; '))
397
+ })
398
+
399
+ // Ends the session this script opened.
400
+ await fetch(`${BASE_URL}/api/auth/sign-out`, { method: 'POST', headers: { cookie, origin: BASE_URL, 'content-type': 'application/json' }, body: '{}', signal: AbortSignal.timeout(60_000) }).catch(() => {})
401
+ }
402
+ }
403
+
404
+ console.log(failures ? `\n${failures} check(s) failed.` : '\nAll route checks passed.')
405
+ process.exit(failures ? 1 : 0)
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Fails when the SQLite and Postgres schemas disagree about tables or columns.
3
+ * pnpm check:schemas
4
+ *
5
+ * The repositories are written once and run on both databases, so the two schema files must stay
6
+ * twins: same tables, same column names, same nullability. (Column *types* differ on purpose.)
7
+ * Plugins' own tables get the same check when the plugin registry loads.
8
+ *
9
+ * It also fails when the site's migrations are not in the order of their dates. Drizzle keeps only
10
+ * the date of the newest migration a database has run and runs whatever is dated after it, so a
11
+ * migration dated before one that already ran is skipped without a word. That happens when two
12
+ * branches each add a migration and the one made first is merged second.
13
+ *
14
+ * Not caught: the same merge resolved by slotting the older migration in before the newer one and
15
+ * renumbering. The journal is then in order, yet every database that ran the newer one still skips
16
+ * the older. A migration always goes last, with a date after every one already on `main`.
17
+ */
18
+ import { readFileSync } from 'node:fs'
19
+ import path from 'node:path'
20
+ import { fileURLToPath } from 'node:url'
21
+
22
+ import { compareTables, sqliteShapes } from '../src/db/compare-tables'
23
+ import * as pg from '../src/db/schema/pg'
24
+ import * as sqlite from '../src/db/schema/sqlite'
25
+
26
+ const problems = compareTables(sqlite, pg)
27
+ if (problems.length) {
28
+ console.error(`The schemas have drifted:\n - ${problems.join('\n - ')}`)
29
+ process.exit(1)
30
+ }
31
+
32
+ type Journal = { entries: { idx: number; when: number; tag: string }[] }
33
+ // Drizzle's migrator reads only the dates; the numbers are drizzle-kit's, which names the next
34
+ // migration and its snapshot after them.
35
+ const misnumbered: string[] = []
36
+ const outOfOrder: string[] = []
37
+ const appDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
38
+ for (const dialect of ['sqlite', 'pg']) {
39
+ const file = path.join(appDir, 'drizzle', dialect, 'meta', '_journal.json')
40
+ const shown = path.relative(process.cwd(), file)
41
+ const { entries } = JSON.parse(readFileSync(file, 'utf8')) as Journal
42
+ entries.forEach((entry, i) => {
43
+ if (entry.idx !== i) misnumbered.push(`${shown}: ${entry.tag} is entry ${i} but numbered ${entry.idx}`)
44
+ const before = entries[i - 1]
45
+ if (before && entry.when <= before.when) outOfOrder.push(`${shown}: ${entry.tag} is dated ${new Date(entry.when).toISOString()}, not after ${before.tag} (${new Date(before.when).toISOString()})`)
46
+ })
47
+ }
48
+ if (misnumbered.length) console.error(`The journal's numbering is broken (each entry's idx must be its place in the list):\n - ${misnumbered.join('\n - ')}`)
49
+ if (outOfOrder.length) {
50
+ console.error(
51
+ `The migrations are out of order, so a database that already ran the later one would skip the earlier:\n - ${outOfOrder.join('\n - ')}\n` +
52
+ 'Make the newer migration again on top of the current ones: for sqlite and pg, delete its .sql file, its meta/<number>_snapshot.json and its entry in meta/_journal.json, run pnpm db:generate, and put back any hand edits to the SQL.\n' +
53
+ 'Only for a migration that has not been released: never re-date one a database may have run.',
54
+ )
55
+ }
56
+ if (misnumbered.length || outOfOrder.length) process.exit(1)
57
+
58
+ console.log(`Schemas match (${sqliteShapes(sqlite).size} tables).`)
@@ -0,0 +1,25 @@
1
+ // Everything `pnpm migrate` does, as one function, so the migrate script and the build-time step
2
+ // (migrate-on-build.ts) can never drift apart. Imported by scripts only.
3
+ import { closeDatabase, getDatabase } from '../src/db/client'
4
+ import { runMigrations } from '../src/db/migrate'
5
+
6
+ export async function migrateAll(): Promise<void> {
7
+ // Slow DDL (building an index on a big table) must not be cut off by the app's query timeout.
8
+ process.env.DB_STATEMENT_TIMEOUT_MS ??= '0'
9
+ const { migratePlugins } = await import('../src/plugins/storage')
10
+ const database = await getDatabase()
11
+ try {
12
+ await runMigrations(database)
13
+ // Rows saved before the folded search columns existed (migration 0011): folding is JavaScript.
14
+ const { backfillSearchText } = await import('../src/server/search-text')
15
+ const filled = await backfillSearchText()
16
+ if (filled.pets || filled.media) console.log(`Filled the search text of ${filled.pets} pets and ${filled.media} images.`)
17
+ // After the site's own, which create plugin_migrations. A plugin's failure stops here with the reason.
18
+ for (const { plugin, ran } of await migratePlugins(database, { throwOnError: true })) {
19
+ if (ran.length) console.log(`Plugin "${plugin}": ran ${ran.join(', ')}.`)
20
+ }
21
+ console.log(`Migrations are up to date (${database.dialect}).`)
22
+ } finally {
23
+ await closeDatabase()
24
+ }
25
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The first half of `pnpm build` (the site's build script runs it, then `next build`), so a deploy's
3
+ * database is migrated before the new code goes live. It is part of the build script itself, not a
4
+ * separate task, so it runs however the build is started.
5
+ *
6
+ * PostgreSQL, hosted libSQL (Turso) migrates, exactly like `pnpm migrate`. A failure fails the
7
+ * build, so code never ships against an older schema.
8
+ * a local SQLite file skipped: it migrates itself when the server opens it, and a
9
+ * build must never create the database file.
10
+ * a Vercel preview build skipped (VERCEL_ENV is not "production"): a preview usually
11
+ * shares the production DATABASE_URL, and a branch must not
12
+ * change that schema before it is merged. MIGRATE_ON_PREVIEW=1
13
+ * runs them anyway, for previews with a database of their own.
14
+ * SKIP_BUILD_MIGRATE=1 skipped: for builds that cannot reach the database (a
15
+ * Docker image built without it). Run `pnpm migrate` before
16
+ * starting the server then.
17
+ * the demo (PET_ADOPT_DEMO=1) skipped: each server instance makes its own throwaway copy.
18
+ * With DATABASE_URL, DATABASE_AUTH_TOKEN or an S3_* setting
19
+ * present the build stops instead, as the server would refuse
20
+ * to start (src/lib/demo.ts).
21
+ *
22
+ * Nothing may cache the build step away: a cache hit would skip this.
23
+ */
24
+ import { isRemoteSqlite, resolveDatabaseUrl } from '../src/db/client'
25
+ import { demoProblem, isDemo } from '../src/lib/demo'
26
+ import { describeError } from '../src/server/result'
27
+
28
+ const flag = (name: string) => ['1', 'true'].includes(process.env[name]?.trim().toLowerCase() ?? '')
29
+
30
+ if (isDemo()) {
31
+ const problem = demoProblem()
32
+ if (problem) {
33
+ console.error(`Build: ${problem}`)
34
+ process.exit(1)
35
+ }
36
+ console.log('Build: the demo (PET_ADOPT_DEMO=1) makes a throwaway database on each server instance, so there is nothing to migrate.')
37
+ process.exit(0)
38
+ }
39
+
40
+ if (flag('SKIP_BUILD_MIGRATE')) {
41
+ console.log('Build: SKIP_BUILD_MIGRATE is set, so migrations are not run. Run `pnpm migrate` before starting the server.')
42
+ process.exit(0)
43
+ }
44
+
45
+ const vercelEnv = process.env.VERCEL_ENV
46
+ if (vercelEnv && vercelEnv !== 'production' && !flag('MIGRATE_ON_PREVIEW')) {
47
+ console.log(`Build: a Vercel ${vercelEnv} build, so migrations are not run (set MIGRATE_ON_PREVIEW=1 if it has its own database).`)
48
+ process.exit(0)
49
+ }
50
+
51
+ const { dialect, url } = resolveDatabaseUrl()
52
+ const remote = dialect === 'pg' || isRemoteSqlite(url)
53
+ if (!remote) {
54
+ console.log('Build: the database is a local SQLite file, which migrates itself when the server opens it. Nothing to do.')
55
+ process.exit(0)
56
+ }
57
+
58
+ console.log(`Build: migrating the ${dialect === 'pg' ? 'PostgreSQL' : 'hosted libSQL'} database before building.`)
59
+ const { migrateAll } = await import('./migrate-all')
60
+ try {
61
+ await migrateAll()
62
+ process.exit(0)
63
+ } catch (error) {
64
+ // Never the error object: database errors carry the bound values, and build logs are often shared.
65
+ console.error(`Migration failed: ${describeError(error)}`)
66
+ console.error(
67
+ '\nThe build stops here so the new code is not deployed against an older schema. Check DATABASE_URL and that the ' +
68
+ 'build can reach the database, or set SKIP_BUILD_MIGRATE=1 and run `pnpm migrate` before starting the server.',
69
+ )
70
+ process.exit(1)
71
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Applies pending database migrations.
3
+ * pnpm migrate
4
+ *
5
+ * A local SQLite file also migrates itself the first time the app opens it. PostgreSQL and hosted
6
+ * libSQL (Turso) never do, because several servers can share them: run this before starting the
7
+ * server, again after every `pnpm db:generate`, and after adding or updating a plugin that has
8
+ * tables of its own (the server warns at start while one is waiting). `pnpm build` runs it too, for
9
+ * PostgreSQL and hosted libSQL (see migrate-on-build.ts).
10
+ */
11
+ import { describeError } from '../src/server/result'
12
+ import { migrateAll } from './migrate-all'
13
+
14
+ try {
15
+ await migrateAll()
16
+ } catch (error) {
17
+ // Never the error object: database errors carry the bound values (records, emails).
18
+ console.error(`Migration failed: ${describeError(error)}`)
19
+ process.exit(1)
20
+ }