@react-consulting/rc-kit 0.0.0-stage → 0.13.1

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 (337) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -2
  3. package/devkit/README.md +301 -0
  4. package/devkit/cli.test.ts +211 -0
  5. package/devkit/cli.ts +120 -0
  6. package/devkit/commands/build.ts +127 -0
  7. package/devkit/commands/checks.ts +123 -0
  8. package/devkit/commands/context.ts +47 -0
  9. package/devkit/commands/db.ts +154 -0
  10. package/devkit/commands/deploy.ts +46 -0
  11. package/devkit/commands/dev.ts +191 -0
  12. package/devkit/commands/doctor.ts +25 -0
  13. package/devkit/commands/kit.ts +45 -0
  14. package/devkit/commands/new.ts +81 -0
  15. package/devkit/commands/registry.ts +20 -0
  16. package/devkit/commands/secrets.ts +254 -0
  17. package/devkit/lib/args.ts +65 -0
  18. package/devkit/lib/audit.test.ts +405 -0
  19. package/devkit/lib/audit.ts +813 -0
  20. package/devkit/lib/config.test.ts +203 -0
  21. package/devkit/lib/config.ts +417 -0
  22. package/devkit/lib/database/index.test.ts +223 -0
  23. package/devkit/lib/database/index.ts +314 -0
  24. package/devkit/lib/database/neon.test.ts +233 -0
  25. package/devkit/lib/database/neon.ts +357 -0
  26. package/devkit/lib/database/prepare.ts +54 -0
  27. package/devkit/lib/deploy-config.test.ts +217 -0
  28. package/devkit/lib/deploy-config.ts +133 -0
  29. package/devkit/lib/deploy.test.ts +275 -0
  30. package/devkit/lib/deploy.ts +177 -0
  31. package/devkit/lib/dev-gateway.test.ts +128 -0
  32. package/devkit/lib/dev-gateway.ts +162 -0
  33. package/devkit/lib/dev-menu.test.ts +114 -0
  34. package/devkit/lib/dev-menu.ts +332 -0
  35. package/devkit/lib/dev-secrets.test.ts +156 -0
  36. package/devkit/lib/dev-secrets.ts +97 -0
  37. package/devkit/lib/dev.test.ts +194 -0
  38. package/devkit/lib/dev.ts +119 -0
  39. package/devkit/lib/doctor.test.ts +144 -0
  40. package/devkit/lib/doctor.ts +264 -0
  41. package/devkit/lib/env-file.test.ts +102 -0
  42. package/devkit/lib/env-file.ts +96 -0
  43. package/devkit/lib/glob.ts +31 -0
  44. package/devkit/lib/infisical.test.ts +208 -0
  45. package/devkit/lib/infisical.ts +139 -0
  46. package/devkit/lib/json-schema.ts +220 -0
  47. package/devkit/lib/jsonc.test.ts +53 -0
  48. package/devkit/lib/jsonc.ts +93 -0
  49. package/devkit/lib/kit-migrate.test.ts +215 -0
  50. package/devkit/lib/kit-migrate.ts +624 -0
  51. package/devkit/lib/kit-package.test.ts +83 -0
  52. package/devkit/lib/kit-package.ts +57 -0
  53. package/devkit/lib/kit-version.ts +22 -0
  54. package/devkit/lib/naming.test.ts +547 -0
  55. package/devkit/lib/naming.ts +796 -0
  56. package/devkit/lib/paths.ts +7 -0
  57. package/devkit/lib/process.ts +78 -0
  58. package/devkit/lib/project-checks.ts +86 -0
  59. package/devkit/lib/scaffold.test.ts +302 -0
  60. package/devkit/lib/scaffold.ts +315 -0
  61. package/devkit/lib/secrets.test.ts +101 -0
  62. package/devkit/lib/secrets.ts +125 -0
  63. package/devkit/lib/sourcemaps.test.ts +86 -0
  64. package/devkit/lib/sourcemaps.ts +98 -0
  65. package/devkit/lib/test-utils.ts +68 -0
  66. package/devkit/lib/workspace.ts +87 -0
  67. package/devkit/lib/wrangler.ts +231 -0
  68. package/docs/rc-config.md +93 -0
  69. package/package.json +86 -4
  70. package/presets/build.d.ts +15 -0
  71. package/presets/build.js +53 -0
  72. package/presets/vite-plus.d.ts +28 -0
  73. package/presets/vite-plus.js +153 -0
  74. package/registry/README.md +294 -0
  75. package/registry/public/r/avatar-stack.json +18 -0
  76. package/registry/public/r/avatar.json +20 -0
  77. package/registry/public/r/back-link.json +21 -0
  78. package/registry/public/r/badge.json +17 -0
  79. package/registry/public/r/button.json +18 -0
  80. package/registry/public/r/calendar-days.json +14 -0
  81. package/registry/public/r/calendar-popover.json +24 -0
  82. package/registry/public/r/calendar.json +23 -0
  83. package/registry/public/r/callout.json +20 -0
  84. package/registry/public/r/card.json +18 -0
  85. package/registry/public/r/character-counter.json +17 -0
  86. package/registry/public/r/checkbox.json +22 -0
  87. package/registry/public/r/choice-cards.json +22 -0
  88. package/registry/public/r/color-tag.json +17 -0
  89. package/registry/public/r/combobox.json +24 -0
  90. package/registry/public/r/confirm-button.json +24 -0
  91. package/registry/public/r/confirm-dialog.json +23 -0
  92. package/registry/public/r/copy-button.json +24 -0
  93. package/registry/public/r/date-picker.json +24 -0
  94. package/registry/public/r/date-range-picker.json +28 -0
  95. package/registry/public/r/detail-header.json +17 -0
  96. package/registry/public/r/detail-row.json +17 -0
  97. package/registry/public/r/dev-inbox-api.json +33 -0
  98. package/registry/public/r/dev-toolbar.json +109 -0
  99. package/registry/public/r/dev-tools-contract.json +15 -0
  100. package/registry/public/r/dialog.json +23 -0
  101. package/registry/public/r/empty-state.json +20 -0
  102. package/registry/public/r/error-state.json +23 -0
  103. package/registry/public/r/eyebrow.json +17 -0
  104. package/registry/public/r/fab.json +20 -0
  105. package/registry/public/r/field-error.json +17 -0
  106. package/registry/public/r/field-grid.json +17 -0
  107. package/registry/public/r/field.json +19 -0
  108. package/registry/public/r/file-picker.json +22 -0
  109. package/registry/public/r/filter-chips.json +17 -0
  110. package/registry/public/r/form-section.json +17 -0
  111. package/registry/public/r/form-sheet.json +22 -0
  112. package/registry/public/r/icon-button.json +23 -0
  113. package/registry/public/r/input.json +18 -0
  114. package/registry/public/r/label.json +18 -0
  115. package/registry/public/r/list-row.json +17 -0
  116. package/registry/public/r/loading-state.json +18 -0
  117. package/registry/public/r/localized-field.json +23 -0
  118. package/registry/public/r/markdown-text.json +17 -0
  119. package/registry/public/r/menu.json +21 -0
  120. package/registry/public/r/money-input.json +17 -0
  121. package/registry/public/r/month-day-select.json +18 -0
  122. package/registry/public/r/numbered-step.json +20 -0
  123. package/registry/public/r/page-actions.json +14 -0
  124. package/registry/public/r/page-header.json +17 -0
  125. package/registry/public/r/pending.json +17 -0
  126. package/registry/public/r/person-option.json +21 -0
  127. package/registry/public/r/popover.json +20 -0
  128. package/registry/public/r/progress-bar.json +17 -0
  129. package/registry/public/r/query-view.json +22 -0
  130. package/registry/public/r/registry.json +1352 -0
  131. package/registry/public/r/retry-button.json +21 -0
  132. package/registry/public/r/rich-text-editor.json +32 -0
  133. package/registry/public/r/save-bar.json +22 -0
  134. package/registry/public/r/search-input.json +23 -0
  135. package/registry/public/r/search-select.json +24 -0
  136. package/registry/public/r/section-tabs.json +17 -0
  137. package/registry/public/r/segmented.json +18 -0
  138. package/registry/public/r/select.json +23 -0
  139. package/registry/public/r/sheet.json +24 -0
  140. package/registry/public/r/skeleton.json +17 -0
  141. package/registry/public/r/spinner.json +20 -0
  142. package/registry/public/r/stale-notice.json +23 -0
  143. package/registry/public/r/stat-tile.json +23 -0
  144. package/registry/public/r/stepper.json +23 -0
  145. package/registry/public/r/suggestion-strip.json +21 -0
  146. package/registry/public/r/swatch-picker.json +22 -0
  147. package/registry/public/r/switch.json +21 -0
  148. package/registry/public/r/tabs.json +20 -0
  149. package/registry/public/r/textarea.json +18 -0
  150. package/registry/public/r/theme.json +15 -0
  151. package/registry/public/r/timezone-select.json +19 -0
  152. package/registry/public/r/toaster.json +21 -0
  153. package/registry/public/r/tooltip.json +17 -0
  154. package/registry/public/r/ui-labels.json +14 -0
  155. package/registry/public/r/use-copy-to-clipboard.json +20 -0
  156. package/registry/public/r/use-online.json +14 -0
  157. package/registry/public/r/use-stale-queries.json +17 -0
  158. package/registry/public/r/utils.json +18 -0
  159. package/registry/public/r/weekday-picker.json +19 -0
  160. package/registry/public/r/yes-no.json +20 -0
  161. package/registry/serve.ts +29 -0
  162. package/rules/architecture.md +47 -0
  163. package/rules/cloudflare.md +74 -0
  164. package/rules/code.md +12 -0
  165. package/rules/git.md +10 -0
  166. package/rules/index.md +14 -0
  167. package/rules/observability.md +13 -0
  168. package/rules/performance.md +39 -0
  169. package/rules/runtime.md +9 -0
  170. package/rules/secrets.md +11 -0
  171. package/rules/stack.md +33 -0
  172. package/rules/ui.md +23 -0
  173. package/runtime/ai.test.ts +106 -0
  174. package/runtime/ai.ts +125 -0
  175. package/runtime/observability/allowlists.ts +42 -0
  176. package/runtime/observability/anonymize.test.ts +111 -0
  177. package/runtime/observability/anonymize.ts +249 -0
  178. package/runtime/observability/browser.test.ts +46 -0
  179. package/runtime/observability/browser.ts +126 -0
  180. package/runtime/observability/server.test.ts +84 -0
  181. package/runtime/observability/server.ts +152 -0
  182. package/runtime/observability/tunnel.test.ts +276 -0
  183. package/runtime/observability/tunnel.ts +360 -0
  184. package/runtime/observability/user-agent.ts +51 -0
  185. package/schema/rc.config.schema.json +333 -0
  186. package/template/.gitattributes +1 -0
  187. package/template/.github/workflows/ci.yml +64 -0
  188. package/template/CLAUDE.md +48 -0
  189. package/template/README.md +50 -0
  190. package/template/apps/admin/.dev.vars.example +5 -0
  191. package/template/apps/admin/components.json +24 -0
  192. package/template/apps/admin/package.json +48 -0
  193. package/template/apps/admin/public/favicon.svg +1 -0
  194. package/template/apps/admin/src/components/app-shell.tsx +41 -0
  195. package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
  196. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
  197. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
  198. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
  199. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
  200. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
  201. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
  202. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
  203. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
  204. package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
  205. package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
  206. package/template/apps/admin/src/components/login-form.tsx +115 -0
  207. package/template/apps/admin/src/components/login-sent.tsx +23 -0
  208. package/template/apps/admin/src/components/message-list.tsx +44 -0
  209. package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
  210. package/template/apps/admin/src/components/ui/button.tsx +87 -0
  211. package/template/apps/admin/src/components/ui/callout.tsx +84 -0
  212. package/template/apps/admin/src/components/ui/card.tsx +48 -0
  213. package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
  214. package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
  215. package/template/apps/admin/src/components/ui/field.tsx +100 -0
  216. package/template/apps/admin/src/components/ui/input.tsx +73 -0
  217. package/template/apps/admin/src/components/ui/label.tsx +39 -0
  218. package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
  219. package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
  220. package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
  221. package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
  222. package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
  223. package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
  224. package/template/apps/admin/src/lib/api.ts +39 -0
  225. package/template/apps/admin/src/lib/auth-client.ts +7 -0
  226. package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
  227. package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
  228. package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
  229. package/template/apps/admin/src/lib/messages.ts +5 -0
  230. package/template/apps/admin/src/lib/query-keys.ts +3 -0
  231. package/template/apps/admin/src/lib/security-headers.ts +18 -0
  232. package/template/apps/admin/src/lib/session.ts +27 -0
  233. package/template/apps/admin/src/lib/site-url.ts +7 -0
  234. package/template/apps/admin/src/lib/turnstile.ts +70 -0
  235. package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
  236. package/template/apps/admin/src/lib/utils.ts +6 -0
  237. package/template/apps/admin/src/routeTree.gen.ts +109 -0
  238. package/template/apps/admin/src/router.tsx +29 -0
  239. package/template/apps/admin/src/routes/__root.tsx +56 -0
  240. package/template/apps/admin/src/routes/_app/index.tsx +38 -0
  241. package/template/apps/admin/src/routes/_app.tsx +26 -0
  242. package/template/apps/admin/src/routes/login.tsx +48 -0
  243. package/template/apps/admin/src/styles/app.css +11 -0
  244. package/template/apps/admin/src/worker.ts +88 -0
  245. package/template/apps/admin/tsconfig.json +19 -0
  246. package/template/apps/admin/vite.config.ts +69 -0
  247. package/template/apps/admin/wrangler.jsonc +92 -0
  248. package/template/apps/web/.env.example +1 -0
  249. package/template/apps/web/astro.config.ts +46 -0
  250. package/template/apps/web/package.json +33 -0
  251. package/template/apps/web/public/favicon.svg +1 -0
  252. package/template/apps/web/src/components/ContactForm.astro +78 -0
  253. package/template/apps/web/src/env.d.ts +11 -0
  254. package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
  255. package/template/apps/web/src/lib/api.ts +8 -0
  256. package/template/apps/web/src/pages/api/messages.ts +32 -0
  257. package/template/apps/web/src/pages/index.astro +26 -0
  258. package/template/apps/web/src/pages/media/[...key].ts +4 -0
  259. package/template/apps/web/src/scripts/contact-form.ts +105 -0
  260. package/template/apps/web/src/scripts/error-reporting.ts +4 -0
  261. package/template/apps/web/src/scripts/turnstile.ts +177 -0
  262. package/template/apps/web/src/styles/global.css +11 -0
  263. package/template/apps/web/src/worker.ts +34 -0
  264. package/template/apps/web/tsconfig.json +11 -0
  265. package/template/apps/web/wrangler.jsonc +45 -0
  266. package/template/bun.lock +1925 -0
  267. package/template/bunfig.toml +2 -0
  268. package/template/gitignore +23 -0
  269. package/template/package.json +74 -0
  270. package/template/packages/api/components.json +21 -0
  271. package/template/packages/api/package.json +30 -0
  272. package/template/packages/api/src/client.ts +13 -0
  273. package/template/packages/api/src/cloudflare-env.d.ts +26 -0
  274. package/template/packages/api/src/emails/escape-html.ts +13 -0
  275. package/template/packages/api/src/emails/layout.ts +22 -0
  276. package/template/packages/api/src/emails/magic-link.ts +32 -0
  277. package/template/packages/api/src/emails/new-message.ts +32 -0
  278. package/template/packages/api/src/emails/send.ts +14 -0
  279. package/template/packages/api/src/lib/auth-guard.ts +16 -0
  280. package/template/packages/api/src/lib/auth.ts +108 -0
  281. package/template/packages/api/src/lib/context.ts +7 -0
  282. package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
  283. package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
  284. package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
  285. package/template/packages/api/src/lib/dev-inbox.ts +6 -0
  286. package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
  287. package/template/packages/api/src/lib/environment.ts +17 -0
  288. package/template/packages/api/src/lib/turnstile.ts +33 -0
  289. package/template/packages/api/src/media.ts +45 -0
  290. package/template/packages/api/src/routes/admin-messages.ts +21 -0
  291. package/template/packages/api/src/routes/dev.ts +31 -0
  292. package/template/packages/api/src/routes/health.ts +7 -0
  293. package/template/packages/api/src/routes/messages.ts +58 -0
  294. package/template/packages/api/src/schemas.ts +18 -0
  295. package/template/packages/api/src/server.ts +29 -0
  296. package/template/packages/api/tsconfig.json +10 -0
  297. package/template/packages/db/migrations/0001_init.sql +79 -0
  298. package/template/packages/db/package.json +34 -0
  299. package/template/packages/db/prisma/schema.prisma +95 -0
  300. package/template/packages/db/prisma.config.ts +9 -0
  301. package/template/packages/db/scripts/migrate.ts +15 -0
  302. package/template/packages/db/scripts/new-migration.ts +185 -0
  303. package/template/packages/db/scripts/reset.ts +54 -0
  304. package/template/packages/db/scripts/seed.ts +44 -0
  305. package/template/packages/db/scripts/wrangler.ts +35 -0
  306. package/template/packages/db/src/d1.ts +7 -0
  307. package/template/packages/db/src/migration-guard.test.ts +43 -0
  308. package/template/packages/db/src/migration-guard.ts +51 -0
  309. package/template/packages/db/src/new-migration.test.ts +16 -0
  310. package/template/packages/db/src/scope.ts +38 -0
  311. package/template/packages/db/src/seed.ts +30 -0
  312. package/template/packages/db/src/sql.ts +42 -0
  313. package/template/packages/db/tsconfig.json +8 -0
  314. package/template/packages/shared/components.json +21 -0
  315. package/template/packages/shared/package.json +33 -0
  316. package/template/packages/shared/src/edge/origins.ts +20 -0
  317. package/template/packages/shared/src/edge/turnstile.ts +11 -0
  318. package/template/packages/shared/src/locales.ts +13 -0
  319. package/template/packages/shared/src/message-rules.ts +16 -0
  320. package/template/packages/shared/src/messages.test.ts +26 -0
  321. package/template/packages/shared/src/messages.ts +30 -0
  322. package/template/packages/shared/src/observability/build-release.ts +9 -0
  323. package/template/packages/shared/src/observability/error-reporting.ts +31 -0
  324. package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
  325. package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
  326. package/template/packages/shared/src/observability/server-errors.ts +74 -0
  327. package/template/packages/shared/src/project.ts +1 -0
  328. package/template/packages/shared/src/styles/rc-theme.css +138 -0
  329. package/template/packages/shared/src/styles/theme.css +9 -0
  330. package/template/packages/shared/tsconfig.json +10 -0
  331. package/template/rc.config.json +25 -0
  332. package/template/scripts/bootstrap-local.ts +42 -0
  333. package/template/tsconfig.base.json +20 -0
  334. package/template/tsconfig.json +8 -0
  335. package/template/tsconfig.worker.json +7 -0
  336. package/template/turbo.json +40 -0
  337. package/template/vite.config.ts +8 -0
@@ -0,0 +1,32 @@
1
+ import { lazy, Suspense, useSyncExternalStore } from "react"
2
+ import type { DevToolbarProps } from "@/components/dev-toolbar/dev-toolbar"
3
+
4
+ // Folded to nothing in production builds, so the toolbar chunk is never emitted.
5
+ const DevToolbar = import.meta.env.DEV
6
+ ? lazy(() =>
7
+ import("@/components/dev-toolbar/dev-toolbar").then((module) => ({
8
+ default: module.DevToolbar,
9
+ }))
10
+ )
11
+ : () => null
12
+
13
+ const noSubscription = () => () => undefined
14
+
15
+ /** Mount once in the root layout, inside the QueryClientProvider; renders nothing outside `vite dev`. */
16
+ export function DevelopmentDevtools(props: DevToolbarProps) {
17
+ const mounted = useSyncExternalStore(
18
+ noSubscription,
19
+ () => true,
20
+ () => false
21
+ )
22
+
23
+ if (!(import.meta.env.DEV && mounted)) {
24
+ return null
25
+ }
26
+
27
+ return (
28
+ <Suspense fallback={null}>
29
+ <DevToolbar {...props} />
30
+ </Suspense>
31
+ )
32
+ }
@@ -0,0 +1,115 @@
1
+ import { CAPTCHA_HEADER } from "@tpl/shared/edge/turnstile"
2
+ import { type FormEvent, useRef, useState } from "react"
3
+ import {
4
+ TurnstileChallenge,
5
+ type TTurnstileHandle,
6
+ } from "@/components/turnstile-challenge"
7
+ import { Button } from "@/components/ui/button"
8
+ import { Callout } from "@/components/ui/callout"
9
+ import { Card } from "@/components/ui/card"
10
+ import { Field } from "@/components/ui/field"
11
+ import { Input } from "@/components/ui/input"
12
+ import { authClient } from "@/lib/auth-client"
13
+
14
+ const CAPTCHA_UNAVAILABLE =
15
+ "La vérification anti-robot n'a pas pu se charger. Vérifiez votre connexion, puis réessayez."
16
+ const CAPTCHA_ERROR_CODES = new Set(["VERIFICATION_FAILED", "MISSING_RESPONSE"])
17
+
18
+ function sendErrorMessage({
19
+ status,
20
+ code,
21
+ }: {
22
+ status: number
23
+ code?: string
24
+ }): string {
25
+ if (status === 429) {
26
+ return "Trop de demandes. Patientez une minute avant de réessayer."
27
+ }
28
+
29
+ if (status === 403 || (code && CAPTCHA_ERROR_CODES.has(code))) {
30
+ return "La vérification anti-robot a échoué. Réessayez dans quelques secondes."
31
+ }
32
+
33
+ return "L'envoi du lien a échoué. Réessayez."
34
+ }
35
+
36
+ export interface TLoginFormProps {
37
+ initialError: string | null
38
+ onSent: (email: string) => void
39
+ }
40
+
41
+ export function LoginForm({ initialError, onSent }: TLoginFormProps) {
42
+ const turnstile = useRef<TTurnstileHandle>(null)
43
+ const [error, setError] = useState(initialError)
44
+ const [pending, setPending] = useState(false)
45
+
46
+ async function captchaToken(): Promise<string | null | undefined> {
47
+ try {
48
+ return (await turnstile.current?.getToken()) ?? null
49
+ } catch {
50
+ turnstile.current?.reset()
51
+ return undefined
52
+ }
53
+ }
54
+
55
+ async function onSubmit(event: FormEvent<HTMLFormElement>) {
56
+ event.preventDefault()
57
+
58
+ const email = String(new FormData(event.currentTarget).get("email")).trim()
59
+
60
+ setPending(true)
61
+ setError(null)
62
+
63
+ const token = await captchaToken()
64
+
65
+ if (token === undefined) {
66
+ setPending(false)
67
+ setError(CAPTCHA_UNAVAILABLE)
68
+ return
69
+ }
70
+
71
+ const { error: sendError } = await authClient.signIn.magicLink({
72
+ email,
73
+ callbackURL: "/",
74
+ errorCallbackURL: "/login",
75
+ fetchOptions: token
76
+ ? { headers: { [CAPTCHA_HEADER]: token } }
77
+ : undefined,
78
+ })
79
+
80
+ turnstile.current?.reset()
81
+ setPending(false)
82
+
83
+ if (sendError) {
84
+ setError(sendErrorMessage(sendError))
85
+ return
86
+ }
87
+
88
+ onSent(email)
89
+ }
90
+
91
+ return (
92
+ <Card
93
+ title="Connexion"
94
+ description="Recevez un lien de connexion par e-mail, sans mot de passe."
95
+ >
96
+ <form onSubmit={onSubmit} className="flex flex-col gap-5">
97
+ <Field label="Adresse e-mail" htmlFor="email">
98
+ <Input
99
+ id="email"
100
+ name="email"
101
+ type="email"
102
+ required
103
+ autoComplete="email"
104
+ placeholder="vous@exemple.com"
105
+ />
106
+ </Field>
107
+ {error ? <Callout title={error} /> : null}
108
+ <TurnstileChallenge ref={turnstile} action="admin-login" />
109
+ <Button type="submit" variant="primary" loading={pending}>
110
+ Recevoir mon lien
111
+ </Button>
112
+ </form>
113
+ </Card>
114
+ )
115
+ }
@@ -0,0 +1,23 @@
1
+ import { MailCheck } from "lucide-react"
2
+ import { Button } from "@/components/ui/button"
3
+ import { Card } from "@/components/ui/card"
4
+
5
+ export interface TLoginSentProps {
6
+ email: string
7
+ onReset: () => void
8
+ }
9
+
10
+ export function LoginSent({ email, onReset }: TLoginSentProps) {
11
+ return (
12
+ <Card title="Vérifiez vos e-mails">
13
+ <div className="flex flex-col gap-5">
14
+ <MailCheck aria-hidden="true" className="size-8 text-success" />
15
+ <p className="text-sm leading-relaxed text-ink-2">
16
+ Si <strong className="font-semibold text-ink">{email}</strong> a accès
17
+ au back office, un lien valable 15 minutes vient de lui être envoyé.
18
+ </p>
19
+ <Button onClick={onReset}>Utiliser une autre adresse</Button>
20
+ </div>
21
+ </Card>
22
+ )
23
+ }
@@ -0,0 +1,44 @@
1
+ import type { TMessageSummary } from "@tpl/shared/messages"
2
+ import { Inbox } from "lucide-react"
3
+
4
+ const DATE_FORMAT = new Intl.DateTimeFormat("fr-FR", {
5
+ dateStyle: "medium",
6
+ timeStyle: "short",
7
+ })
8
+
9
+ export function MessageList({ messages }: { messages: TMessageSummary[] }) {
10
+ if (messages.length === 0) {
11
+ return (
12
+ <div className="flex flex-col items-center gap-3 px-6 py-12 text-center">
13
+ <Inbox aria-hidden="true" className="size-6 text-ink-4" />
14
+ <p className="text-sm text-ink-3">Aucun message pour l'instant.</p>
15
+ </div>
16
+ )
17
+ }
18
+
19
+ return (
20
+ <ul className="divide-y divide-line">
21
+ {messages.map((message) => (
22
+ <li key={message.id} className="flex flex-col gap-1.5 px-5 py-4">
23
+ <div className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
24
+ <p className="text-sm font-semibold text-ink">
25
+ {message.name}{" "}
26
+ <a
27
+ href={`mailto:${message.email}`}
28
+ className="font-normal text-ink-2 underline-offset-2 hover:underline"
29
+ >
30
+ {message.email}
31
+ </a>
32
+ </p>
33
+ <time dateTime={message.createdAt} className="text-xs text-ink-3">
34
+ {DATE_FORMAT.format(new Date(message.createdAt))}
35
+ </time>
36
+ </div>
37
+ <p className="text-sm leading-relaxed whitespace-pre-line text-ink-2">
38
+ {message.body}
39
+ </p>
40
+ </li>
41
+ ))}
42
+ </ul>
43
+ )
44
+ }
@@ -0,0 +1,140 @@
1
+ import { type Ref, useEffect, useImperativeHandle, useRef } from "react"
2
+ import { loadTurnstile, turnstileSiteKey } from "@/lib/turnstile"
3
+
4
+ const TOKEN_TIMEOUT_MS = 20_000
5
+
6
+ export interface TTurnstileHandle {
7
+ /** Resolves `null` when no site key is configured: the API then decides whether a captcha is required. */
8
+ getToken: () => Promise<string | null>
9
+ reset: () => void
10
+ }
11
+
12
+ interface TWaiter {
13
+ resolve: (token: string) => void
14
+ reject: (error: Error) => void
15
+ }
16
+
17
+ export interface TTurnstileChallengeProps {
18
+ ref: Ref<TTurnstileHandle>
19
+ action?: string
20
+ }
21
+
22
+ /** Invisible widget: it solves in the background as soon as the page loads, and only shows up if Cloudflare asks for an interaction. */
23
+ export function TurnstileChallenge({ ref, action }: TTurnstileChallengeProps) {
24
+ const container = useRef<HTMLDivElement>(null)
25
+ const widgetId = useRef<string | null>(null)
26
+ const token = useRef<string | null>(null)
27
+ const failure = useRef<Error | null>(null)
28
+ const waiters = useRef<TWaiter[]>([])
29
+ const siteKey = turnstileSiteKey()
30
+
31
+ function settle(result: { token: string } | { error: Error }) {
32
+ const pending = waiters.current
33
+ waiters.current = []
34
+
35
+ for (const waiter of pending) {
36
+ if ("token" in result) {
37
+ waiter.resolve(result.token)
38
+ } else {
39
+ waiter.reject(result.error)
40
+ }
41
+ }
42
+ }
43
+
44
+ useEffect(() => {
45
+ if (!siteKey) {
46
+ return
47
+ }
48
+
49
+ let cancelled = false
50
+
51
+ loadTurnstile()
52
+ .then((turnstile) => {
53
+ if (cancelled || !container.current) {
54
+ return
55
+ }
56
+
57
+ widgetId.current = turnstile.render(container.current, {
58
+ sitekey: siteKey,
59
+ action,
60
+ appearance: "interaction-only",
61
+ language: "fr",
62
+ "refresh-expired": "auto",
63
+ callback: (value) => {
64
+ token.current = value
65
+ failure.current = null
66
+ settle({ token: value })
67
+ },
68
+ "error-callback": (code) => {
69
+ token.current = null
70
+ failure.current = new Error(`turnstile-${code}`)
71
+ settle({ error: failure.current })
72
+ },
73
+ "expired-callback": () => {
74
+ token.current = null
75
+ },
76
+ })
77
+ })
78
+ .catch((error: Error) => {
79
+ failure.current = error
80
+ settle({ error })
81
+ })
82
+
83
+ return () => {
84
+ cancelled = true
85
+ if (widgetId.current) {
86
+ window.turnstile?.remove(widgetId.current)
87
+ widgetId.current = null
88
+ }
89
+ }
90
+ }, [siteKey, action])
91
+
92
+ useImperativeHandle(ref, () => ({
93
+ getToken() {
94
+ if (!siteKey) {
95
+ return Promise.resolve(null)
96
+ }
97
+ if (token.current) {
98
+ return Promise.resolve(token.current)
99
+ }
100
+ if (failure.current) {
101
+ return Promise.reject(failure.current)
102
+ }
103
+
104
+ return new Promise<string>((resolve, reject) => {
105
+ const timer = window.setTimeout(() => {
106
+ waiters.current = waiters.current.filter(
107
+ (waiter) => waiter.resolve !== onToken
108
+ )
109
+ reject(new Error("turnstile-timeout"))
110
+ }, TOKEN_TIMEOUT_MS)
111
+
112
+ function onToken(value: string) {
113
+ window.clearTimeout(timer)
114
+ resolve(value)
115
+ }
116
+
117
+ waiters.current.push({
118
+ resolve: onToken,
119
+ reject: (error) => {
120
+ window.clearTimeout(timer)
121
+ reject(error)
122
+ },
123
+ })
124
+ })
125
+ },
126
+ reset() {
127
+ token.current = null
128
+ failure.current = null
129
+ if (widgetId.current) {
130
+ window.turnstile?.reset(widgetId.current)
131
+ }
132
+ },
133
+ }))
134
+
135
+ if (!siteKey) {
136
+ return null
137
+ }
138
+
139
+ return <div ref={container} className="flex justify-center empty:hidden" />
140
+ }
@@ -0,0 +1,87 @@
1
+ import type { ButtonHTMLAttributes, Ref } from "react"
2
+ import { Spinner } from "@/components/ui/spinner"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ export type ButtonVariant =
6
+ | "primary"
7
+ | "ink"
8
+ | "secondary"
9
+ | "ghost"
10
+ | "danger"
11
+ | "destructive"
12
+
13
+ export type ButtonSize = "sm" | "md" | "lg"
14
+
15
+ const VARIANTS: Record<ButtonVariant, string> = {
16
+ primary: "bg-accent text-accent-ink hover:bg-accent-deep disabled:bg-ink-4",
17
+ ink: "bg-ink text-chalk hover:bg-night-2 disabled:bg-ink-4",
18
+ secondary:
19
+ "border border-line-strong bg-surface text-ink hover:bg-paper disabled:border-line disabled:text-ink-3",
20
+ ghost: "text-ink-2 hover:bg-ink/5 hover:text-ink disabled:text-ink-3",
21
+ danger:
22
+ "border border-line bg-surface text-danger hover:border-danger hover:bg-danger-soft disabled:border-line disabled:text-ink-3",
23
+ destructive: "bg-danger text-chalk hover:bg-danger/90 disabled:bg-ink-4",
24
+ }
25
+
26
+ const SIZES: Record<ButtonSize, string> = {
27
+ sm: "min-h-9 gap-1.5 px-3 text-sm pointer-coarse:min-h-11",
28
+ md: "min-h-10 gap-2 px-4 text-sm",
29
+ lg: "min-h-12 gap-2.5 px-6 text-base",
30
+ }
31
+
32
+ export interface ButtonLook {
33
+ className?: string
34
+ size?: ButtonSize
35
+ variant?: ButtonVariant
36
+ }
37
+
38
+ export function buttonClassName({
39
+ variant = "secondary",
40
+ size = "md",
41
+ className,
42
+ }: ButtonLook = {}): string {
43
+ return cn(
44
+ "inline-flex select-none items-center justify-center rounded-md font-medium leading-none whitespace-nowrap",
45
+ "transition-[background-color,color,border-color,transform] duration-200 ease-out-expo",
46
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
47
+ "active:translate-y-px disabled:cursor-not-allowed disabled:active:translate-y-0",
48
+ VARIANTS[variant],
49
+ SIZES[size],
50
+ className
51
+ )
52
+ }
53
+
54
+ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
55
+ loading?: boolean
56
+ ref?: Ref<HTMLButtonElement>
57
+ size?: ButtonSize
58
+ variant?: ButtonVariant
59
+ }
60
+
61
+ export function Button({
62
+ className,
63
+ variant = "secondary",
64
+ size = "md",
65
+ type = "button",
66
+ loading = false,
67
+ disabled = false,
68
+ children,
69
+ ...props
70
+ }: ButtonProps) {
71
+ return (
72
+ <button
73
+ aria-busy={loading || undefined}
74
+ className={buttonClassName({
75
+ className: cn(loading && "disabled:cursor-progress", className),
76
+ size,
77
+ variant,
78
+ })}
79
+ disabled={disabled || loading}
80
+ type={type}
81
+ {...props}
82
+ >
83
+ {loading ? <Spinner /> : null}
84
+ {children}
85
+ </button>
86
+ )
87
+ }
@@ -0,0 +1,84 @@
1
+ import {
2
+ CircleAlert,
3
+ CircleCheck,
4
+ Info,
5
+ type LucideIcon,
6
+ TriangleAlert,
7
+ } from "lucide-react"
8
+ import type { ReactNode } from "react"
9
+ import { cn } from "@/lib/utils"
10
+
11
+ export type CalloutTone = "danger" | "success" | "warn" | "info"
12
+
13
+ const TONES: Record<
14
+ CalloutTone,
15
+ { box: string; icon: LucideIcon; iconClassName: string }
16
+ > = {
17
+ danger: {
18
+ box: "border-danger bg-danger-soft",
19
+ icon: CircleAlert,
20
+ iconClassName: "text-danger",
21
+ },
22
+ info: {
23
+ box: "border-accent bg-accent-soft",
24
+ icon: Info,
25
+ iconClassName: "text-accent",
26
+ },
27
+ success: {
28
+ box: "border-success bg-success-soft",
29
+ icon: CircleCheck,
30
+ iconClassName: "text-success",
31
+ },
32
+ warn: {
33
+ box: "border-warn bg-warn-soft",
34
+ icon: TriangleAlert,
35
+ iconClassName: "text-warn",
36
+ },
37
+ }
38
+
39
+ export interface CalloutProps {
40
+ /** Sits under the text: a link or a small button that resolves the situation. */
41
+ action?: ReactNode
42
+ children?: ReactNode
43
+ className?: string
44
+ icon?: LucideIcon
45
+ title: string
46
+ tone?: CalloutTone
47
+ }
48
+
49
+ export function Callout({
50
+ tone = "danger",
51
+ title,
52
+ icon,
53
+ action,
54
+ className,
55
+ children,
56
+ }: CalloutProps) {
57
+ const look = TONES[tone]
58
+ const Icon = icon ?? look.icon
59
+
60
+ return (
61
+ <div
62
+ className={cn(
63
+ "reveal flex gap-3 rounded-md border-l-4 px-4 py-3 text-sm",
64
+ look.box,
65
+ className
66
+ )}
67
+ role={tone === "danger" ? "alert" : "status"}
68
+ >
69
+ <Icon
70
+ aria-hidden="true"
71
+ className={cn("mt-0.5 size-4 shrink-0", look.iconClassName)}
72
+ />
73
+ <div className="flex min-w-0 flex-col gap-1">
74
+ <p className="font-semibold leading-snug text-ink">{title}</p>
75
+ {children ? (
76
+ <div className="leading-snug text-ink-2">{children}</div>
77
+ ) : null}
78
+ {action ? (
79
+ <div className="mt-1 flex flex-wrap gap-2">{action}</div>
80
+ ) : null}
81
+ </div>
82
+ </div>
83
+ )
84
+ }
@@ -0,0 +1,48 @@
1
+ import type { ReactNode } from "react"
2
+ import { Eyebrow } from "@/components/ui/eyebrow"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ export interface CardProps {
6
+ actions?: ReactNode
7
+ children: ReactNode
8
+ className?: string
9
+ description?: string
10
+ eyebrow?: string
11
+ /** No padding around the body: for a `List`, a table or a picture. */
12
+ flush?: boolean
13
+ title?: string
14
+ }
15
+
16
+ export function Card({
17
+ title,
18
+ eyebrow,
19
+ description,
20
+ actions,
21
+ flush = false,
22
+ children,
23
+ className,
24
+ }: CardProps) {
25
+ return (
26
+ <section
27
+ className={cn("rounded-lg border border-line bg-surface", className)}
28
+ >
29
+ {title ? (
30
+ <header className="flex flex-wrap items-start justify-between gap-x-6 gap-y-3 border-b border-line px-5 py-4 sm:px-6">
31
+ <div className="flex min-w-0 flex-col gap-1">
32
+ {eyebrow ? <Eyebrow tone="accent">{eyebrow}</Eyebrow> : null}
33
+ <h2 className="font-display text-lg font-semibold leading-tight text-ink">
34
+ {title}
35
+ </h2>
36
+ {description ? (
37
+ <p className="text-sm leading-snug text-ink-2">{description}</p>
38
+ ) : null}
39
+ </div>
40
+ {actions ? (
41
+ <div className="flex shrink-0 items-center gap-2">{actions}</div>
42
+ ) : null}
43
+ </header>
44
+ ) : null}
45
+ <div className={flush ? undefined : "px-5 py-5 sm:px-6"}>{children}</div>
46
+ </section>
47
+ )
48
+ }
@@ -0,0 +1,33 @@
1
+ import type { ReactNode } from "react"
2
+ import { cn } from "@/lib/utils"
3
+
4
+ export type EyebrowTone = "muted" | "strong" | "accent" | "chalk"
5
+
6
+ const TONES: Record<EyebrowTone, string> = {
7
+ muted: "text-ink-3",
8
+ strong: "text-ink-2",
9
+ accent: "text-accent",
10
+ chalk: "text-chalk-2",
11
+ }
12
+
13
+ export function Eyebrow({
14
+ children,
15
+ tone = "muted",
16
+ className,
17
+ }: {
18
+ children: ReactNode
19
+ className?: string
20
+ tone?: EyebrowTone
21
+ }) {
22
+ return (
23
+ <span
24
+ className={cn(
25
+ "text-xs font-semibold uppercase tracking-wider",
26
+ TONES[tone],
27
+ className
28
+ )}
29
+ >
30
+ {children}
31
+ </span>
32
+ )
33
+ }
@@ -0,0 +1,24 @@
1
+ import { CircleAlert } from "lucide-react"
2
+
3
+ export function FieldError({
4
+ children,
5
+ id,
6
+ }: {
7
+ children?: string | null
8
+ id?: string
9
+ }) {
10
+ if (!children) {
11
+ return null
12
+ }
13
+
14
+ return (
15
+ <p
16
+ className="flex items-start gap-1.5 text-sm font-medium leading-snug text-danger"
17
+ id={id}
18
+ role="alert"
19
+ >
20
+ <CircleAlert aria-hidden="true" className="mt-0.5 size-3.5 shrink-0" />
21
+ {children}
22
+ </p>
23
+ )
24
+ }