@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.
- package/LICENSE +21 -0
- package/README.md +93 -2
- package/devkit/README.md +301 -0
- package/devkit/cli.test.ts +211 -0
- package/devkit/cli.ts +120 -0
- package/devkit/commands/build.ts +127 -0
- package/devkit/commands/checks.ts +123 -0
- package/devkit/commands/context.ts +47 -0
- package/devkit/commands/db.ts +154 -0
- package/devkit/commands/deploy.ts +46 -0
- package/devkit/commands/dev.ts +191 -0
- package/devkit/commands/doctor.ts +25 -0
- package/devkit/commands/kit.ts +45 -0
- package/devkit/commands/new.ts +81 -0
- package/devkit/commands/registry.ts +20 -0
- package/devkit/commands/secrets.ts +254 -0
- package/devkit/lib/args.ts +65 -0
- package/devkit/lib/audit.test.ts +405 -0
- package/devkit/lib/audit.ts +813 -0
- package/devkit/lib/config.test.ts +203 -0
- package/devkit/lib/config.ts +417 -0
- package/devkit/lib/database/index.test.ts +223 -0
- package/devkit/lib/database/index.ts +314 -0
- package/devkit/lib/database/neon.test.ts +233 -0
- package/devkit/lib/database/neon.ts +357 -0
- package/devkit/lib/database/prepare.ts +54 -0
- package/devkit/lib/deploy-config.test.ts +217 -0
- package/devkit/lib/deploy-config.ts +133 -0
- package/devkit/lib/deploy.test.ts +275 -0
- package/devkit/lib/deploy.ts +177 -0
- package/devkit/lib/dev-gateway.test.ts +128 -0
- package/devkit/lib/dev-gateway.ts +162 -0
- package/devkit/lib/dev-menu.test.ts +114 -0
- package/devkit/lib/dev-menu.ts +332 -0
- package/devkit/lib/dev-secrets.test.ts +156 -0
- package/devkit/lib/dev-secrets.ts +97 -0
- package/devkit/lib/dev.test.ts +194 -0
- package/devkit/lib/dev.ts +119 -0
- package/devkit/lib/doctor.test.ts +144 -0
- package/devkit/lib/doctor.ts +264 -0
- package/devkit/lib/env-file.test.ts +102 -0
- package/devkit/lib/env-file.ts +96 -0
- package/devkit/lib/glob.ts +31 -0
- package/devkit/lib/infisical.test.ts +208 -0
- package/devkit/lib/infisical.ts +139 -0
- package/devkit/lib/json-schema.ts +220 -0
- package/devkit/lib/jsonc.test.ts +53 -0
- package/devkit/lib/jsonc.ts +93 -0
- package/devkit/lib/kit-migrate.test.ts +215 -0
- package/devkit/lib/kit-migrate.ts +624 -0
- package/devkit/lib/kit-package.test.ts +83 -0
- package/devkit/lib/kit-package.ts +57 -0
- package/devkit/lib/kit-version.ts +22 -0
- package/devkit/lib/naming.test.ts +547 -0
- package/devkit/lib/naming.ts +796 -0
- package/devkit/lib/paths.ts +7 -0
- package/devkit/lib/process.ts +78 -0
- package/devkit/lib/project-checks.ts +86 -0
- package/devkit/lib/scaffold.test.ts +302 -0
- package/devkit/lib/scaffold.ts +315 -0
- package/devkit/lib/secrets.test.ts +101 -0
- package/devkit/lib/secrets.ts +125 -0
- package/devkit/lib/sourcemaps.test.ts +86 -0
- package/devkit/lib/sourcemaps.ts +98 -0
- package/devkit/lib/test-utils.ts +68 -0
- package/devkit/lib/workspace.ts +87 -0
- package/devkit/lib/wrangler.ts +231 -0
- package/docs/rc-config.md +93 -0
- package/package.json +86 -4
- package/presets/build.d.ts +15 -0
- package/presets/build.js +53 -0
- package/presets/vite-plus.d.ts +28 -0
- package/presets/vite-plus.js +153 -0
- package/registry/README.md +294 -0
- package/registry/public/r/avatar-stack.json +18 -0
- package/registry/public/r/avatar.json +20 -0
- package/registry/public/r/back-link.json +21 -0
- package/registry/public/r/badge.json +17 -0
- package/registry/public/r/button.json +18 -0
- package/registry/public/r/calendar-days.json +14 -0
- package/registry/public/r/calendar-popover.json +24 -0
- package/registry/public/r/calendar.json +23 -0
- package/registry/public/r/callout.json +20 -0
- package/registry/public/r/card.json +18 -0
- package/registry/public/r/character-counter.json +17 -0
- package/registry/public/r/checkbox.json +22 -0
- package/registry/public/r/choice-cards.json +22 -0
- package/registry/public/r/color-tag.json +17 -0
- package/registry/public/r/combobox.json +24 -0
- package/registry/public/r/confirm-button.json +24 -0
- package/registry/public/r/confirm-dialog.json +23 -0
- package/registry/public/r/copy-button.json +24 -0
- package/registry/public/r/date-picker.json +24 -0
- package/registry/public/r/date-range-picker.json +28 -0
- package/registry/public/r/detail-header.json +17 -0
- package/registry/public/r/detail-row.json +17 -0
- package/registry/public/r/dev-inbox-api.json +33 -0
- package/registry/public/r/dev-toolbar.json +109 -0
- package/registry/public/r/dev-tools-contract.json +15 -0
- package/registry/public/r/dialog.json +23 -0
- package/registry/public/r/empty-state.json +20 -0
- package/registry/public/r/error-state.json +23 -0
- package/registry/public/r/eyebrow.json +17 -0
- package/registry/public/r/fab.json +20 -0
- package/registry/public/r/field-error.json +17 -0
- package/registry/public/r/field-grid.json +17 -0
- package/registry/public/r/field.json +19 -0
- package/registry/public/r/file-picker.json +22 -0
- package/registry/public/r/filter-chips.json +17 -0
- package/registry/public/r/form-section.json +17 -0
- package/registry/public/r/form-sheet.json +22 -0
- package/registry/public/r/icon-button.json +23 -0
- package/registry/public/r/input.json +18 -0
- package/registry/public/r/label.json +18 -0
- package/registry/public/r/list-row.json +17 -0
- package/registry/public/r/loading-state.json +18 -0
- package/registry/public/r/localized-field.json +23 -0
- package/registry/public/r/markdown-text.json +17 -0
- package/registry/public/r/menu.json +21 -0
- package/registry/public/r/money-input.json +17 -0
- package/registry/public/r/month-day-select.json +18 -0
- package/registry/public/r/numbered-step.json +20 -0
- package/registry/public/r/page-actions.json +14 -0
- package/registry/public/r/page-header.json +17 -0
- package/registry/public/r/pending.json +17 -0
- package/registry/public/r/person-option.json +21 -0
- package/registry/public/r/popover.json +20 -0
- package/registry/public/r/progress-bar.json +17 -0
- package/registry/public/r/query-view.json +22 -0
- package/registry/public/r/registry.json +1352 -0
- package/registry/public/r/retry-button.json +21 -0
- package/registry/public/r/rich-text-editor.json +32 -0
- package/registry/public/r/save-bar.json +22 -0
- package/registry/public/r/search-input.json +23 -0
- package/registry/public/r/search-select.json +24 -0
- package/registry/public/r/section-tabs.json +17 -0
- package/registry/public/r/segmented.json +18 -0
- package/registry/public/r/select.json +23 -0
- package/registry/public/r/sheet.json +24 -0
- package/registry/public/r/skeleton.json +17 -0
- package/registry/public/r/spinner.json +20 -0
- package/registry/public/r/stale-notice.json +23 -0
- package/registry/public/r/stat-tile.json +23 -0
- package/registry/public/r/stepper.json +23 -0
- package/registry/public/r/suggestion-strip.json +21 -0
- package/registry/public/r/swatch-picker.json +22 -0
- package/registry/public/r/switch.json +21 -0
- package/registry/public/r/tabs.json +20 -0
- package/registry/public/r/textarea.json +18 -0
- package/registry/public/r/theme.json +15 -0
- package/registry/public/r/timezone-select.json +19 -0
- package/registry/public/r/toaster.json +21 -0
- package/registry/public/r/tooltip.json +17 -0
- package/registry/public/r/ui-labels.json +14 -0
- package/registry/public/r/use-copy-to-clipboard.json +20 -0
- package/registry/public/r/use-online.json +14 -0
- package/registry/public/r/use-stale-queries.json +17 -0
- package/registry/public/r/utils.json +18 -0
- package/registry/public/r/weekday-picker.json +19 -0
- package/registry/public/r/yes-no.json +20 -0
- package/registry/serve.ts +29 -0
- package/rules/architecture.md +47 -0
- package/rules/cloudflare.md +74 -0
- package/rules/code.md +12 -0
- package/rules/git.md +10 -0
- package/rules/index.md +14 -0
- package/rules/observability.md +13 -0
- package/rules/performance.md +39 -0
- package/rules/runtime.md +9 -0
- package/rules/secrets.md +11 -0
- package/rules/stack.md +33 -0
- package/rules/ui.md +23 -0
- package/runtime/ai.test.ts +106 -0
- package/runtime/ai.ts +125 -0
- package/runtime/observability/allowlists.ts +42 -0
- package/runtime/observability/anonymize.test.ts +111 -0
- package/runtime/observability/anonymize.ts +249 -0
- package/runtime/observability/browser.test.ts +46 -0
- package/runtime/observability/browser.ts +126 -0
- package/runtime/observability/server.test.ts +84 -0
- package/runtime/observability/server.ts +152 -0
- package/runtime/observability/tunnel.test.ts +276 -0
- package/runtime/observability/tunnel.ts +360 -0
- package/runtime/observability/user-agent.ts +51 -0
- package/schema/rc.config.schema.json +333 -0
- package/template/.gitattributes +1 -0
- package/template/.github/workflows/ci.yml +64 -0
- package/template/CLAUDE.md +48 -0
- package/template/README.md +50 -0
- package/template/apps/admin/.dev.vars.example +5 -0
- package/template/apps/admin/components.json +24 -0
- package/template/apps/admin/package.json +48 -0
- package/template/apps/admin/public/favicon.svg +1 -0
- package/template/apps/admin/src/components/app-shell.tsx +41 -0
- package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
- package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
- package/template/apps/admin/src/components/login-form.tsx +115 -0
- package/template/apps/admin/src/components/login-sent.tsx +23 -0
- package/template/apps/admin/src/components/message-list.tsx +44 -0
- package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
- package/template/apps/admin/src/components/ui/button.tsx +87 -0
- package/template/apps/admin/src/components/ui/callout.tsx +84 -0
- package/template/apps/admin/src/components/ui/card.tsx +48 -0
- package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
- package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
- package/template/apps/admin/src/components/ui/field.tsx +100 -0
- package/template/apps/admin/src/components/ui/input.tsx +73 -0
- package/template/apps/admin/src/components/ui/label.tsx +39 -0
- package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
- package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
- package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
- package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
- package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
- package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
- package/template/apps/admin/src/lib/api.ts +39 -0
- package/template/apps/admin/src/lib/auth-client.ts +7 -0
- package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
- package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
- package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
- package/template/apps/admin/src/lib/messages.ts +5 -0
- package/template/apps/admin/src/lib/query-keys.ts +3 -0
- package/template/apps/admin/src/lib/security-headers.ts +18 -0
- package/template/apps/admin/src/lib/session.ts +27 -0
- package/template/apps/admin/src/lib/site-url.ts +7 -0
- package/template/apps/admin/src/lib/turnstile.ts +70 -0
- package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
- package/template/apps/admin/src/lib/utils.ts +6 -0
- package/template/apps/admin/src/routeTree.gen.ts +109 -0
- package/template/apps/admin/src/router.tsx +29 -0
- package/template/apps/admin/src/routes/__root.tsx +56 -0
- package/template/apps/admin/src/routes/_app/index.tsx +38 -0
- package/template/apps/admin/src/routes/_app.tsx +26 -0
- package/template/apps/admin/src/routes/login.tsx +48 -0
- package/template/apps/admin/src/styles/app.css +11 -0
- package/template/apps/admin/src/worker.ts +88 -0
- package/template/apps/admin/tsconfig.json +19 -0
- package/template/apps/admin/vite.config.ts +69 -0
- package/template/apps/admin/wrangler.jsonc +92 -0
- package/template/apps/web/.env.example +1 -0
- package/template/apps/web/astro.config.ts +46 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/public/favicon.svg +1 -0
- package/template/apps/web/src/components/ContactForm.astro +78 -0
- package/template/apps/web/src/env.d.ts +11 -0
- package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
- package/template/apps/web/src/lib/api.ts +8 -0
- package/template/apps/web/src/pages/api/messages.ts +32 -0
- package/template/apps/web/src/pages/index.astro +26 -0
- package/template/apps/web/src/pages/media/[...key].ts +4 -0
- package/template/apps/web/src/scripts/contact-form.ts +105 -0
- package/template/apps/web/src/scripts/error-reporting.ts +4 -0
- package/template/apps/web/src/scripts/turnstile.ts +177 -0
- package/template/apps/web/src/styles/global.css +11 -0
- package/template/apps/web/src/worker.ts +34 -0
- package/template/apps/web/tsconfig.json +11 -0
- package/template/apps/web/wrangler.jsonc +45 -0
- package/template/bun.lock +1925 -0
- package/template/bunfig.toml +2 -0
- package/template/gitignore +23 -0
- package/template/package.json +74 -0
- package/template/packages/api/components.json +21 -0
- package/template/packages/api/package.json +30 -0
- package/template/packages/api/src/client.ts +13 -0
- package/template/packages/api/src/cloudflare-env.d.ts +26 -0
- package/template/packages/api/src/emails/escape-html.ts +13 -0
- package/template/packages/api/src/emails/layout.ts +22 -0
- package/template/packages/api/src/emails/magic-link.ts +32 -0
- package/template/packages/api/src/emails/new-message.ts +32 -0
- package/template/packages/api/src/emails/send.ts +14 -0
- package/template/packages/api/src/lib/auth-guard.ts +16 -0
- package/template/packages/api/src/lib/auth.ts +108 -0
- package/template/packages/api/src/lib/context.ts +7 -0
- package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
- package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
- package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
- package/template/packages/api/src/lib/dev-inbox.ts +6 -0
- package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
- package/template/packages/api/src/lib/environment.ts +17 -0
- package/template/packages/api/src/lib/turnstile.ts +33 -0
- package/template/packages/api/src/media.ts +45 -0
- package/template/packages/api/src/routes/admin-messages.ts +21 -0
- package/template/packages/api/src/routes/dev.ts +31 -0
- package/template/packages/api/src/routes/health.ts +7 -0
- package/template/packages/api/src/routes/messages.ts +58 -0
- package/template/packages/api/src/schemas.ts +18 -0
- package/template/packages/api/src/server.ts +29 -0
- package/template/packages/api/tsconfig.json +10 -0
- package/template/packages/db/migrations/0001_init.sql +79 -0
- package/template/packages/db/package.json +34 -0
- package/template/packages/db/prisma/schema.prisma +95 -0
- package/template/packages/db/prisma.config.ts +9 -0
- package/template/packages/db/scripts/migrate.ts +15 -0
- package/template/packages/db/scripts/new-migration.ts +185 -0
- package/template/packages/db/scripts/reset.ts +54 -0
- package/template/packages/db/scripts/seed.ts +44 -0
- package/template/packages/db/scripts/wrangler.ts +35 -0
- package/template/packages/db/src/d1.ts +7 -0
- package/template/packages/db/src/migration-guard.test.ts +43 -0
- package/template/packages/db/src/migration-guard.ts +51 -0
- package/template/packages/db/src/new-migration.test.ts +16 -0
- package/template/packages/db/src/scope.ts +38 -0
- package/template/packages/db/src/seed.ts +30 -0
- package/template/packages/db/src/sql.ts +42 -0
- package/template/packages/db/tsconfig.json +8 -0
- package/template/packages/shared/components.json +21 -0
- package/template/packages/shared/package.json +33 -0
- package/template/packages/shared/src/edge/origins.ts +20 -0
- package/template/packages/shared/src/edge/turnstile.ts +11 -0
- package/template/packages/shared/src/locales.ts +13 -0
- package/template/packages/shared/src/message-rules.ts +16 -0
- package/template/packages/shared/src/messages.test.ts +26 -0
- package/template/packages/shared/src/messages.ts +30 -0
- package/template/packages/shared/src/observability/build-release.ts +9 -0
- package/template/packages/shared/src/observability/error-reporting.ts +31 -0
- package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
- package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
- package/template/packages/shared/src/observability/server-errors.ts +74 -0
- package/template/packages/shared/src/project.ts +1 -0
- package/template/packages/shared/src/styles/rc-theme.css +138 -0
- package/template/packages/shared/src/styles/theme.css +9 -0
- package/template/packages/shared/tsconfig.json +10 -0
- package/template/rc.config.json +25 -0
- package/template/scripts/bootstrap-local.ts +42 -0
- package/template/tsconfig.base.json +20 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.worker.json +7 -0
- package/template/turbo.json +40 -0
- package/template/vite.config.ts +8 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
3
|
+
import { MessageList } from "@/components/message-list"
|
|
4
|
+
import { Card } from "@/components/ui/card"
|
|
5
|
+
import { Spinner } from "@/components/ui/spinner"
|
|
6
|
+
import { fetchMessages } from "@/lib/messages"
|
|
7
|
+
import { QUERY_KEYS } from "@/lib/query-keys"
|
|
8
|
+
|
|
9
|
+
export const Route = createFileRoute("/_app/")({
|
|
10
|
+
component: DashboardPage,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
function DashboardPage() {
|
|
14
|
+
const messages = useQuery({
|
|
15
|
+
queryKey: QUERY_KEYS.messages,
|
|
16
|
+
queryFn: fetchMessages,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Card
|
|
21
|
+
title="Messages"
|
|
22
|
+
description="Les demandes envoyées depuis le formulaire de contact du site."
|
|
23
|
+
flush
|
|
24
|
+
>
|
|
25
|
+
{messages.data ? (
|
|
26
|
+
<MessageList messages={messages.data} />
|
|
27
|
+
) : (
|
|
28
|
+
<div className="grid place-items-center p-10 text-ink-3">
|
|
29
|
+
{messages.isError ? (
|
|
30
|
+
<p className="text-sm text-danger">Chargement impossible.</p>
|
|
31
|
+
) : (
|
|
32
|
+
<Spinner />
|
|
33
|
+
)}
|
|
34
|
+
</div>
|
|
35
|
+
)}
|
|
36
|
+
</Card>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router"
|
|
2
|
+
import { AppShell } from "@/components/app-shell"
|
|
3
|
+
import { getSessionUser } from "@/lib/session"
|
|
4
|
+
|
|
5
|
+
export const Route = createFileRoute("/_app")({
|
|
6
|
+
beforeLoad: async () => {
|
|
7
|
+
const user = await getSessionUser()
|
|
8
|
+
|
|
9
|
+
if (!user) {
|
|
10
|
+
throw redirect({ to: "/login" })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return { user }
|
|
14
|
+
},
|
|
15
|
+
component: AppLayout,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
function AppLayout() {
|
|
19
|
+
const { user } = Route.useRouteContext()
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<AppShell user={user}>
|
|
23
|
+
<Outlet />
|
|
24
|
+
</AppShell>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
2
|
+
import { createFileRoute, redirect } from "@tanstack/react-router"
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
import { LoginForm } from "@/components/login-form"
|
|
5
|
+
import { LoginSent } from "@/components/login-sent"
|
|
6
|
+
import { getSessionUser } from "@/lib/session"
|
|
7
|
+
|
|
8
|
+
const LINK_ERRORS: Record<string, string> = {
|
|
9
|
+
INVALID_TOKEN: "Ce lien a déjà servi ou n'est plus valable.",
|
|
10
|
+
EXPIRED_TOKEN: "Ce lien a expiré. Demandez-en un nouveau.",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Route = createFileRoute("/login")({
|
|
14
|
+
validateSearch: (search: Record<string, unknown>): { error?: string } => ({
|
|
15
|
+
error: typeof search.error === "string" ? search.error : undefined,
|
|
16
|
+
}),
|
|
17
|
+
beforeLoad: async () => {
|
|
18
|
+
if (await getSessionUser()) {
|
|
19
|
+
throw redirect({ to: "/" })
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
head: () => ({ meta: [{ title: `Connexion · ${PROJECT_TITLE}` }] }),
|
|
23
|
+
component: LoginPage,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
function LoginPage() {
|
|
27
|
+
const { error } = Route.useSearch()
|
|
28
|
+
const [sentTo, setSentTo] = useState<string | null>(null)
|
|
29
|
+
|
|
30
|
+
const linkError = error
|
|
31
|
+
? (LINK_ERRORS[error] ?? "La connexion a échoué. Réessayez.")
|
|
32
|
+
: null
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<main className="grid min-h-dvh place-items-center bg-paper px-4 py-12">
|
|
36
|
+
<div className="w-full max-w-sm">
|
|
37
|
+
<p className="mb-6 text-center font-display text-sm font-semibold text-ink-3">
|
|
38
|
+
{PROJECT_TITLE}
|
|
39
|
+
</p>
|
|
40
|
+
{sentTo ? (
|
|
41
|
+
<LoginSent email={sentTo} onReset={() => setSentTo(null)} />
|
|
42
|
+
) : (
|
|
43
|
+
<LoginForm initialError={linkError} onSent={setSentTo} />
|
|
44
|
+
)}
|
|
45
|
+
</div>
|
|
46
|
+
</main>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { serveMedia } from "@tpl/api/media"
|
|
2
|
+
import { createD1PrismaClient } from "@tpl/db/d1"
|
|
3
|
+
import { withPrismaClient } from "@tpl/db/scope"
|
|
4
|
+
import {
|
|
5
|
+
ERROR_TUNNEL_PATH,
|
|
6
|
+
serveErrorTunnel,
|
|
7
|
+
} from "@tpl/shared/observability/error-tunnel"
|
|
8
|
+
import {
|
|
9
|
+
reportServerError,
|
|
10
|
+
withErrorTracking,
|
|
11
|
+
} from "@tpl/shared/observability/server-errors"
|
|
12
|
+
import serverEntry from "@tanstack/react-start/server-entry"
|
|
13
|
+
import { withSecurityHeaders } from "./lib/security-headers"
|
|
14
|
+
|
|
15
|
+
type TApp = { handle: (request: Request) => Promise<Response> }
|
|
16
|
+
|
|
17
|
+
let app: TApp | undefined
|
|
18
|
+
|
|
19
|
+
async function loadApi(): Promise<TApp> {
|
|
20
|
+
if (!app) {
|
|
21
|
+
const { createApi } = await import("@tpl/api/server")
|
|
22
|
+
app = createApi()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return app
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isAuthPath(pathname: string): boolean {
|
|
29
|
+
return pathname === "/api/auth" || pathname.startsWith("/api/auth/")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function failureResponse(request: Request, error: unknown): Response {
|
|
33
|
+
const { pathname } = new URL(request.url)
|
|
34
|
+
|
|
35
|
+
reportServerError(error, {
|
|
36
|
+
method: request.method,
|
|
37
|
+
route: pathname,
|
|
38
|
+
surface: pathname.startsWith("/api/") ? "api" : "render",
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return new Response("Internal Server Error", {
|
|
42
|
+
headers: { "cache-control": "no-store" },
|
|
43
|
+
status: 500,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function route(
|
|
48
|
+
request: Request,
|
|
49
|
+
env: Cloudflare.Env,
|
|
50
|
+
ctx: ExecutionContext
|
|
51
|
+
): Promise<Response> {
|
|
52
|
+
const { pathname } = new URL(request.url)
|
|
53
|
+
|
|
54
|
+
if (pathname === ERROR_TUNNEL_PATH) {
|
|
55
|
+
return await serveErrorTunnel(request, env, ctx)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (pathname.startsWith("/media/")) {
|
|
59
|
+
return await serveMedia(request, ctx)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (isAuthPath(pathname)) {
|
|
63
|
+
const { auth } = await import("@tpl/api/server")
|
|
64
|
+
return await auth().handler(request)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (pathname.startsWith("/api/")) {
|
|
68
|
+
return await (await loadApi()).handle(request)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return await serverEntry.fetch(request)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default withErrorTracking("tpl-admin", {
|
|
75
|
+
async fetch(request, env, ctx) {
|
|
76
|
+
const response = withSecurityHeaders(
|
|
77
|
+
await withPrismaClient(createD1PrismaClient(env.DB), () =>
|
|
78
|
+
route(request, env, ctx)
|
|
79
|
+
).catch((error: unknown) => failureResponse(request, error))
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (!new URL(request.url).pathname.startsWith("/media/")) {
|
|
83
|
+
response.headers.set("x-robots-tag", "noindex, nofollow")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return response
|
|
87
|
+
},
|
|
88
|
+
} satisfies ExportedHandler<Cloudflare.Env>)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowImportingTsExtensions": true,
|
|
5
|
+
"jsx": "react-jsx",
|
|
6
|
+
"lib": ["dom", "dom.iterable", "ES2023"],
|
|
7
|
+
"types": ["@cloudflare/workers-types", "vite/client"],
|
|
8
|
+
"paths": {
|
|
9
|
+
"@/*": ["./src/*"]
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"../../packages/api/src/cloudflare-env.d.ts",
|
|
14
|
+
"src/**/*.ts",
|
|
15
|
+
"src/**/*.tsx",
|
|
16
|
+
"vite.config.ts"
|
|
17
|
+
],
|
|
18
|
+
"exclude": ["node_modules", ".tanstack", ".wrangler", "dist"]
|
|
19
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
import { fileURLToPath } from "node:url"
|
|
3
|
+
import { cloudflare } from "@cloudflare/vite-plugin"
|
|
4
|
+
import { DEV_PORTS } from "@tpl/shared/edge/origins"
|
|
5
|
+
import {
|
|
6
|
+
TURNSTILE_SITE_KEY,
|
|
7
|
+
TURNSTILE_TEST_SITE_KEY,
|
|
8
|
+
} from "@tpl/shared/edge/turnstile"
|
|
9
|
+
import tailwindcss from "@tailwindcss/vite"
|
|
10
|
+
import { tanstackStart } from "@tanstack/react-start/plugin/vite"
|
|
11
|
+
import react from "@vitejs/plugin-react"
|
|
12
|
+
import { defineConfig } from "vite-plus"
|
|
13
|
+
import {
|
|
14
|
+
readDeployedPublicEnv,
|
|
15
|
+
resolveBuildCommitSha,
|
|
16
|
+
} from "@react-consulting/rc-kit/build"
|
|
17
|
+
|
|
18
|
+
const ADMIN_DIR = fileURLToPath(new URL(".", import.meta.url))
|
|
19
|
+
|
|
20
|
+
// Found only on the first render, they would make Vite re-optimize mid-request and serve a 500 once.
|
|
21
|
+
const EAGER_DEPS = ["@base-ui/react/tooltip"]
|
|
22
|
+
|
|
23
|
+
function deployedPublicDefines(command: string): Record<string, string> {
|
|
24
|
+
const publicEnv =
|
|
25
|
+
command === "serve" ? {} : readDeployedPublicEnv(ADMIN_DIR, "VITE_")
|
|
26
|
+
|
|
27
|
+
return Object.fromEntries(
|
|
28
|
+
Object.entries(publicEnv).map(([key, value]) => [
|
|
29
|
+
`import.meta.env.${key}`,
|
|
30
|
+
JSON.stringify(value),
|
|
31
|
+
])
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default defineConfig(({ command }) => ({
|
|
36
|
+
define: {
|
|
37
|
+
...deployedPublicDefines(command),
|
|
38
|
+
__RC_BUILD_SHA__: JSON.stringify(resolveBuildCommitSha()),
|
|
39
|
+
"import.meta.env.VITE_TURNSTILE_SITE_KEY": JSON.stringify(
|
|
40
|
+
command === "serve" ? TURNSTILE_TEST_SITE_KEY : TURNSTILE_SITE_KEY
|
|
41
|
+
),
|
|
42
|
+
},
|
|
43
|
+
optimizeDeps: { include: EAGER_DEPS },
|
|
44
|
+
environments: {
|
|
45
|
+
ssr: { optimizeDeps: { include: EAGER_DEPS } },
|
|
46
|
+
},
|
|
47
|
+
build: {
|
|
48
|
+
minify: "oxc",
|
|
49
|
+
sourcemap: "hidden",
|
|
50
|
+
},
|
|
51
|
+
plugins: [
|
|
52
|
+
cloudflare({
|
|
53
|
+
inspectorPort: false,
|
|
54
|
+
viteEnvironment: { name: "ssr" },
|
|
55
|
+
}),
|
|
56
|
+
tanstackStart(),
|
|
57
|
+
react(),
|
|
58
|
+
tailwindcss(),
|
|
59
|
+
],
|
|
60
|
+
resolve: {
|
|
61
|
+
alias: [{ find: "@", replacement: path.join(ADMIN_DIR, "src") }],
|
|
62
|
+
},
|
|
63
|
+
server: {
|
|
64
|
+
// The web Worker's service-binding requests carry this placeholder host.
|
|
65
|
+
allowedHosts: ["api.internal"],
|
|
66
|
+
port: DEV_PORTS.admin,
|
|
67
|
+
strictPort: true,
|
|
68
|
+
},
|
|
69
|
+
}))
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../node_modules/wrangler/config-schema.json",
|
|
3
|
+
"name": "tpl-admin-local",
|
|
4
|
+
"account_id": "00000000000000000000000000000000",
|
|
5
|
+
"main": "src/worker.ts",
|
|
6
|
+
"compatibility_date": "2026-10-01",
|
|
7
|
+
"compatibility_flags": ["nodejs_compat"],
|
|
8
|
+
"workers_dev": false,
|
|
9
|
+
"preview_urls": false,
|
|
10
|
+
"observability": {
|
|
11
|
+
"enabled": true,
|
|
12
|
+
"traces": { "enabled": true, "head_sampling_rate": 1 },
|
|
13
|
+
},
|
|
14
|
+
// The top level is local development: miniflare keeps D1 and R2 under .wrangler/state, keyed by the ids below.
|
|
15
|
+
// Production is env.production, which inherits no binding and no var: every addition goes to both levels.
|
|
16
|
+
"d1_databases": [
|
|
17
|
+
{
|
|
18
|
+
"binding": "DB",
|
|
19
|
+
"database_name": "tpl-d1-local",
|
|
20
|
+
"database_id": "tpl-d1-local",
|
|
21
|
+
"migrations_dir": "../../packages/db/migrations",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
"r2_buckets": [{ "binding": "MEDIA", "bucket_name": "tpl-media-local" }],
|
|
25
|
+
// Locally no e-mail leaves the machine: ENVIRONMENT=local files each one in the dev toolbar's inbox.
|
|
26
|
+
"send_email": [{ "name": "EMAIL" }],
|
|
27
|
+
"ratelimits": [
|
|
28
|
+
{
|
|
29
|
+
"name": "MESSAGES_RATE_LIMITER",
|
|
30
|
+
"namespace_id": "1001",
|
|
31
|
+
"simple": { "limit": 5, "period": 60 },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
"vars": {
|
|
35
|
+
"ENVIRONMENT": "local",
|
|
36
|
+
"PUBLIC_SITE_URL": "http://localhost:4321",
|
|
37
|
+
"ADMIN_URL": "http://localhost:3000",
|
|
38
|
+
"EMAIL_FROM": "no-reply@example.com",
|
|
39
|
+
"ADMIN_EMAILS": "admin@example.com",
|
|
40
|
+
"SENTRY_DSN": "",
|
|
41
|
+
"SENTRY_TUNNEL_DSNS": "",
|
|
42
|
+
"VITE_SENTRY_DSN": "",
|
|
43
|
+
},
|
|
44
|
+
// Secrets come from .dev.vars (`rc secrets:pull` or `bun run bootstrap:local`); wrangler loads only those listed.
|
|
45
|
+
"secrets": {
|
|
46
|
+
"required": ["BETTER_AUTH_SECRET", "TURNSTILE_SECRET_KEY"],
|
|
47
|
+
},
|
|
48
|
+
"env": {
|
|
49
|
+
"production": {
|
|
50
|
+
"observability": {
|
|
51
|
+
"enabled": true,
|
|
52
|
+
"traces": { "enabled": true, "head_sampling_rate": 1 },
|
|
53
|
+
},
|
|
54
|
+
"name": "tpl-admin-prod",
|
|
55
|
+
"upload_source_maps": true,
|
|
56
|
+
"routes": [{ "pattern": "admin.example.com", "custom_domain": true }],
|
|
57
|
+
// The id comes from `wrangler d1 create tpl-d1-prod`; enable read replication on it.
|
|
58
|
+
"d1_databases": [
|
|
59
|
+
{
|
|
60
|
+
"binding": "DB",
|
|
61
|
+
"database_name": "tpl-d1-prod",
|
|
62
|
+
"database_id": "00000000-0000-0000-0000-000000000000",
|
|
63
|
+
"migrations_dir": "../../packages/db/migrations",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
"r2_buckets": [{ "binding": "MEDIA", "bucket_name": "tpl-media-prod" }],
|
|
67
|
+
// Cloudflare Email Service: the sending domain of EMAIL_FROM must be onboarded on the account.
|
|
68
|
+
"send_email": [{ "name": "EMAIL" }],
|
|
69
|
+
"ratelimits": [
|
|
70
|
+
{
|
|
71
|
+
"name": "MESSAGES_RATE_LIMITER",
|
|
72
|
+
"namespace_id": "1001",
|
|
73
|
+
"simple": { "limit": 5, "period": 60 },
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
"vars": {
|
|
77
|
+
"ENVIRONMENT": "production",
|
|
78
|
+
"PUBLIC_SITE_URL": "https://www.example.com",
|
|
79
|
+
"ADMIN_URL": "https://admin.example.com",
|
|
80
|
+
"EMAIL_FROM": "no-reply@example.com",
|
|
81
|
+
"ADMIN_EMAILS": "admin@example.com",
|
|
82
|
+
// The DSN of the Sentry project tpl-admin, the same in all three.
|
|
83
|
+
"SENTRY_DSN": "",
|
|
84
|
+
"SENTRY_TUNNEL_DSNS": "",
|
|
85
|
+
"VITE_SENTRY_DSN": "",
|
|
86
|
+
},
|
|
87
|
+
"secrets": {
|
|
88
|
+
"required": ["BETTER_AUTH_SECRET", "TURNSTILE_SECRET_KEY"],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Written by `rc secrets:pull` from the Infisical project's dev environment, limited to the PUBLIC_* keys.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url"
|
|
2
|
+
import cloudflare from "@astrojs/cloudflare"
|
|
3
|
+
import { DEV_PORTS, SITE_ORIGIN } from "@tpl/shared/edge/origins"
|
|
4
|
+
import tailwindcss from "@tailwindcss/vite"
|
|
5
|
+
import { defineConfig, envField } from "astro/config"
|
|
6
|
+
import {
|
|
7
|
+
readDeployedPublicEnv,
|
|
8
|
+
resolveBuildCommitSha,
|
|
9
|
+
} from "@react-consulting/rc-kit/build"
|
|
10
|
+
|
|
11
|
+
const isBuild = process.argv.includes("build")
|
|
12
|
+
const deployedPublicEnv = isBuild
|
|
13
|
+
? readDeployedPublicEnv(
|
|
14
|
+
fileURLToPath(new URL(".", import.meta.url)),
|
|
15
|
+
"PUBLIC_"
|
|
16
|
+
)
|
|
17
|
+
: {}
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
site: SITE_ORIGIN,
|
|
21
|
+
output: "server",
|
|
22
|
+
session: false,
|
|
23
|
+
adapter: cloudflare({
|
|
24
|
+
imageService: "compile",
|
|
25
|
+
inspectorPort: false,
|
|
26
|
+
}),
|
|
27
|
+
env: {
|
|
28
|
+
schema: {
|
|
29
|
+
PUBLIC_SENTRY_DSN: envField.string({
|
|
30
|
+
context: "client",
|
|
31
|
+
access: "public",
|
|
32
|
+
optional: true,
|
|
33
|
+
default: deployedPublicEnv.PUBLIC_SENTRY_DSN,
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
server: { port: DEV_PORTS.web },
|
|
38
|
+
vite: {
|
|
39
|
+
plugins: [tailwindcss()],
|
|
40
|
+
build: { sourcemap: "hidden" },
|
|
41
|
+
define: {
|
|
42
|
+
__RC_BUILD_SHA__: JSON.stringify(resolveBuildCommitSha()),
|
|
43
|
+
},
|
|
44
|
+
server: { strictPort: true },
|
|
45
|
+
},
|
|
46
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tpl/web",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "MIMALLOC_ALLOW_THP=0 astro dev",
|
|
8
|
+
"build": "astro build",
|
|
9
|
+
"build:cloudflare": "astro build && rc sentry:sourcemaps --app web --directory dist/client --delete-maps && rc sentry:sourcemaps --app web --directory dist/server",
|
|
10
|
+
"preview": "astro preview",
|
|
11
|
+
"check:types": "astro sync && astro-check",
|
|
12
|
+
"deploy:cloudflare": "wrangler deploy",
|
|
13
|
+
"upload:cloudflare": "wrangler versions upload"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@astrojs/cloudflare": "^14.4.7",
|
|
17
|
+
"@tpl/shared": "workspace:*",
|
|
18
|
+
"astro": "^7.4.10"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@astrojs/check": "^0.9.12",
|
|
22
|
+
"@cloudflare/workers-types": "catalog:",
|
|
23
|
+
"@emnapi/core": "^1.11.3",
|
|
24
|
+
"@emnapi/runtime": "^1.11.3",
|
|
25
|
+
"@react-consulting/rc-kit": "link:../..",
|
|
26
|
+
"@sentry/cli": "^3.8.2",
|
|
27
|
+
"@tailwindcss/vite": "catalog:",
|
|
28
|
+
"tailwindcss": "catalog:",
|
|
29
|
+
"typescript": "catalog:",
|
|
30
|
+
"vite": "catalog:",
|
|
31
|
+
"wrangler": "catalog:"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="8" fill="#27272a"/><path d="M10 22V10h7a4 4 0 0 1 0 8h-7m7 0 5 4" fill="none" stroke="#fafafa" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
import {
|
|
3
|
+
TURNSTILE_SITE_KEY,
|
|
4
|
+
TURNSTILE_TEST_SITE_KEY,
|
|
5
|
+
} from "@tpl/shared/edge/turnstile"
|
|
6
|
+
import { MESSAGE_LIMITS } from "@tpl/shared/message-rules"
|
|
7
|
+
|
|
8
|
+
const siteKey = import.meta.env.DEV ? TURNSTILE_TEST_SITE_KEY : TURNSTILE_SITE_KEY
|
|
9
|
+
|
|
10
|
+
const FIELD_CLASS =
|
|
11
|
+
"min-h-10 w-full rounded-md border border-line bg-surface px-3 text-base text-ink placeholder:text-ink-4 hover:border-line-strong focus-visible:border-accent focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-accent/20"
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<form
|
|
15
|
+
data-contact-form
|
|
16
|
+
data-turnstile-site-key={siteKey}
|
|
17
|
+
data-state="idle"
|
|
18
|
+
class="group flex flex-col gap-5 rounded-lg border border-line bg-surface p-6"
|
|
19
|
+
novalidate
|
|
20
|
+
>
|
|
21
|
+
<div class="flex flex-col gap-2">
|
|
22
|
+
<label for="contact-name" class="text-sm font-medium text-ink">Nom</label>
|
|
23
|
+
<input
|
|
24
|
+
id="contact-name"
|
|
25
|
+
name="name"
|
|
26
|
+
required
|
|
27
|
+
autocomplete="name"
|
|
28
|
+
minlength={MESSAGE_LIMITS.name.min}
|
|
29
|
+
maxlength={MESSAGE_LIMITS.name.max}
|
|
30
|
+
class={FIELD_CLASS}
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="flex flex-col gap-2">
|
|
34
|
+
<label for="contact-email" class="text-sm font-medium text-ink">E-mail</label>
|
|
35
|
+
<input
|
|
36
|
+
id="contact-email"
|
|
37
|
+
name="email"
|
|
38
|
+
type="email"
|
|
39
|
+
required
|
|
40
|
+
autocomplete="email"
|
|
41
|
+
maxlength={MESSAGE_LIMITS.email.max}
|
|
42
|
+
class={FIELD_CLASS}
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="flex flex-col gap-2">
|
|
46
|
+
<label for="contact-body" class="text-sm font-medium text-ink">Message</label>
|
|
47
|
+
<textarea
|
|
48
|
+
id="contact-body"
|
|
49
|
+
name="body"
|
|
50
|
+
required
|
|
51
|
+
rows="5"
|
|
52
|
+
minlength={MESSAGE_LIMITS.body.min}
|
|
53
|
+
maxlength={MESSAGE_LIMITS.body.max}
|
|
54
|
+
class:list={[FIELD_CLASS, "py-2"]}></textarea>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="hidden" aria-hidden="true">
|
|
57
|
+
<label for="contact-website">Site web</label>
|
|
58
|
+
<input id="contact-website" name="website" tabindex="-1" autocomplete="off" />
|
|
59
|
+
</div>
|
|
60
|
+
<div data-turnstile-slot></div>
|
|
61
|
+
<p
|
|
62
|
+
data-form-status
|
|
63
|
+
role="status"
|
|
64
|
+
aria-live="polite"
|
|
65
|
+
class="hidden text-sm group-data-[state=error]:block group-data-[state=error]:text-danger group-data-[state=sent]:block group-data-[state=sent]:text-success"
|
|
66
|
+
>
|
|
67
|
+
</p>
|
|
68
|
+
<button
|
|
69
|
+
type="submit"
|
|
70
|
+
class="inline-flex min-h-10 items-center justify-center rounded-md bg-accent px-4 text-sm font-medium text-accent-ink transition-colors hover:bg-accent-deep disabled:cursor-progress disabled:bg-ink-4"
|
|
71
|
+
>
|
|
72
|
+
Envoyer
|
|
73
|
+
</button>
|
|
74
|
+
</form>
|
|
75
|
+
|
|
76
|
+
<script>
|
|
77
|
+
import "@/scripts/contact-form"
|
|
78
|
+
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare namespace Cloudflare {
|
|
2
|
+
interface Env {
|
|
3
|
+
/** The admin Worker (`tpl-admin-*`): it alone reads D1 and R2 and serves the API. */
|
|
4
|
+
API: Fetcher
|
|
5
|
+
ENVIRONMENT: string
|
|
6
|
+
/** Empty outside production: server errors stay local. */
|
|
7
|
+
SENTRY_DSN?: string
|
|
8
|
+
/** Comma-separated DSNs the browser error tunnel may relay to. */
|
|
9
|
+
SENTRY_TUNNEL_DSNS?: string
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
3
|
+
import { DEFAULT_LOCALE, LOCALE_TAGS } from "@tpl/shared/locales"
|
|
4
|
+
import "@/styles/global.css"
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
title?: string
|
|
8
|
+
description?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
title = PROJECT_TITLE,
|
|
13
|
+
description = `${PROJECT_TITLE} : site public.`,
|
|
14
|
+
} = Astro.props
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<!doctype html>
|
|
18
|
+
<html lang={LOCALE_TAGS[DEFAULT_LOCALE]}>
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="utf-8" />
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
22
|
+
<meta name="description" content={description} />
|
|
23
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
|
24
|
+
<title>{title}</title>
|
|
25
|
+
</head>
|
|
26
|
+
<body class="min-h-dvh bg-paper text-ink antialiased">
|
|
27
|
+
<slot />
|
|
28
|
+
<script>
|
|
29
|
+
import "@/scripts/error-reporting"
|
|
30
|
+
</script>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { env } from "cloudflare:workers"
|
|
2
|
+
|
|
3
|
+
// Service-binding requests never leave Cloudflare: the host is only a placeholder.
|
|
4
|
+
const API_ORIGIN = "https://api.internal"
|
|
5
|
+
|
|
6
|
+
export function apiFetch(path: string, init?: RequestInit): Promise<Response> {
|
|
7
|
+
return env.API.fetch(`${API_ORIGIN}${path}`, init)
|
|
8
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MESSAGE_ERRORS } from "@tpl/shared/message-rules"
|
|
2
|
+
import { messageInputSchema } from "@tpl/shared/messages"
|
|
3
|
+
import type { APIRoute } from "astro"
|
|
4
|
+
import { apiFetch } from "@/lib/api"
|
|
5
|
+
|
|
6
|
+
const FORWARDED_HEADERS = ["cf-connecting-ip", "user-agent"]
|
|
7
|
+
|
|
8
|
+
// The form posts same-origin; the admin Worker owns the messages, so the site only checks the contract and relays.
|
|
9
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
10
|
+
const parsed = messageInputSchema.safeParse(
|
|
11
|
+
await request.json().catch(() => null)
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
if (!parsed.success) {
|
|
15
|
+
return Response.json({ message: MESSAGE_ERRORS.invalid }, { status: 400 })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const headers = new Headers({ "content-type": "application/json" })
|
|
19
|
+
|
|
20
|
+
for (const name of FORWARDED_HEADERS) {
|
|
21
|
+
const value = request.headers.get(name)
|
|
22
|
+
if (value) {
|
|
23
|
+
headers.set(name, value)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return apiFetch("/api/messages", {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers,
|
|
30
|
+
body: JSON.stringify(parsed.data),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
3
|
+
import ContactForm from "@/components/ContactForm.astro"
|
|
4
|
+
import BaseLayout from "@/layouts/BaseLayout.astro"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<BaseLayout>
|
|
8
|
+
<main class="mx-auto flex max-w-3xl flex-col gap-16 px-4 py-20">
|
|
9
|
+
<header class="flex flex-col gap-4">
|
|
10
|
+
<p class="text-sm font-semibold text-ink-3">{PROJECT_TITLE}</p>
|
|
11
|
+
<h1 class="font-display text-4xl font-semibold tracking-tight text-balance">
|
|
12
|
+
Un site public Astro, un back office TanStack Start, une API Elysia.
|
|
13
|
+
</h1>
|
|
14
|
+
<p class="max-w-xl text-lg text-ink-2">
|
|
15
|
+
Le site lit tout par le binding de service vers l'admin. Écrivez-nous :
|
|
16
|
+
le message arrive dans le back office.
|
|
17
|
+
</p>
|
|
18
|
+
</header>
|
|
19
|
+
<section aria-labelledby="contact-title" class="flex flex-col gap-6">
|
|
20
|
+
<h2 id="contact-title" class="font-display text-2xl font-semibold">
|
|
21
|
+
Contact
|
|
22
|
+
</h2>
|
|
23
|
+
<ContactForm />
|
|
24
|
+
</section>
|
|
25
|
+
</main>
|
|
26
|
+
</BaseLayout>
|