@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,23 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
|
|
3
|
+
.astro/
|
|
4
|
+
.output/
|
|
5
|
+
.tanstack/
|
|
6
|
+
.turbo/
|
|
7
|
+
.wrangler/
|
|
8
|
+
dist/
|
|
9
|
+
|
|
10
|
+
.dev.vars*
|
|
11
|
+
.env*
|
|
12
|
+
!.dev.vars.example
|
|
13
|
+
!.env.example
|
|
14
|
+
.infisical-token
|
|
15
|
+
|
|
16
|
+
packages/db/src/generated/
|
|
17
|
+
packages/db/.shadow.sqlite
|
|
18
|
+
packages/db/.agents/
|
|
19
|
+
packages/db/.claude/
|
|
20
|
+
packages/db/skills-lock.json
|
|
21
|
+
|
|
22
|
+
.DS_Store
|
|
23
|
+
*.tsbuildinfo
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rc-template",
|
|
3
|
+
"private": true,
|
|
4
|
+
"workspaces": {
|
|
5
|
+
"packages": [
|
|
6
|
+
"apps/*",
|
|
7
|
+
"packages/*"
|
|
8
|
+
],
|
|
9
|
+
"catalog": {
|
|
10
|
+
"@base-ui/react": "^1.9.0",
|
|
11
|
+
"@cloudflare/vite-plugin": "^1.68.0",
|
|
12
|
+
"@cloudflare/workers-types": "^5.20261110.1",
|
|
13
|
+
"@prisma/adapter-d1": "^7.10.1",
|
|
14
|
+
"@prisma/client": "^7.10.1",
|
|
15
|
+
"@tailwindcss/vite": "^4.3.5",
|
|
16
|
+
"@tanstack/react-query": "^5.107.1",
|
|
17
|
+
"@types/bun": "^1.4.4",
|
|
18
|
+
"@types/node": "^26.6.6",
|
|
19
|
+
"@types/react": "~19.3.0",
|
|
20
|
+
"@types/react-dom": "~19.3.0",
|
|
21
|
+
"@typescript/native-preview": "^7.0.0-dev.20260707.2",
|
|
22
|
+
"better-auth": "1.7.20",
|
|
23
|
+
"elysia": "^1.4.31",
|
|
24
|
+
"prisma": "^7.10.1",
|
|
25
|
+
"react": "19.3.0",
|
|
26
|
+
"react-dom": "19.3.0",
|
|
27
|
+
"tailwindcss": "^4.3.5",
|
|
28
|
+
"typescript": "^6.0.3",
|
|
29
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.5.1",
|
|
30
|
+
"vite-plus": "1.5.1",
|
|
31
|
+
"wrangler": "^4.160.0",
|
|
32
|
+
"zod": "^4.6.7"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "rc secrets:pull && turbo run dev",
|
|
38
|
+
"bootstrap:local": "bun scripts/bootstrap-local.ts",
|
|
39
|
+
"build": "turbo run build",
|
|
40
|
+
"build:cloudflare": "turbo run build:cloudflare",
|
|
41
|
+
"lint": "rc check:naming && rc check:deploy-config && vp lint && vp fmt --check",
|
|
42
|
+
"lint:fix": "vp lint --fix && vp fmt",
|
|
43
|
+
"format": "vp fmt",
|
|
44
|
+
"check:types": "turbo run check:types && tsgo --noEmit --pretty false",
|
|
45
|
+
"test": "turbo run test",
|
|
46
|
+
"db:generate": "turbo run db:generate --filter=@tpl/db",
|
|
47
|
+
"db:migrate:new": "bun --cwd=packages/db run db:migrate:new",
|
|
48
|
+
"db:migrate": "bun --cwd=packages/db run db:migrate",
|
|
49
|
+
"db:seed": "bun --cwd=packages/db run db:seed",
|
|
50
|
+
"db:reset": "bun --cwd=packages/db run db:reset",
|
|
51
|
+
"deploy": "rc deploy all",
|
|
52
|
+
"deploy:admin": "rc deploy admin",
|
|
53
|
+
"deploy:web": "rc deploy web",
|
|
54
|
+
"secrets:push": "rc secrets:push",
|
|
55
|
+
"audit": "rc audit",
|
|
56
|
+
"prepare": "vp config"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@react-consulting/rc-kit": "link:..",
|
|
60
|
+
"@tpl/shared": "workspace:*",
|
|
61
|
+
"@types/bun": "catalog:",
|
|
62
|
+
"@types/node": "catalog:",
|
|
63
|
+
"@typescript/native-preview": "catalog:",
|
|
64
|
+
"turbo": "^2.11.10",
|
|
65
|
+
"typescript": "catalog:",
|
|
66
|
+
"vite": "catalog:",
|
|
67
|
+
"vite-plus": "catalog:",
|
|
68
|
+
"wrangler": "catalog:"
|
|
69
|
+
},
|
|
70
|
+
"overrides": {
|
|
71
|
+
"vite": "catalog:"
|
|
72
|
+
},
|
|
73
|
+
"packageManager": "bun@1.4.4"
|
|
74
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "",
|
|
9
|
+
"baseColor": "neutral",
|
|
10
|
+
"cssVariables": false,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"aliases": {
|
|
14
|
+
"components": "@/components",
|
|
15
|
+
"utils": "@/lib/utils",
|
|
16
|
+
"lib": "@/lib"
|
|
17
|
+
},
|
|
18
|
+
"registries": {
|
|
19
|
+
"@rc": "http://localhost:4873/r/{name}.json"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tpl/api",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./client": "./src/client.ts",
|
|
8
|
+
"./server": "./src/server.ts",
|
|
9
|
+
"./media": "./src/media.ts",
|
|
10
|
+
"./cloudflare-env": "./src/cloudflare-env.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"check:types": "tsgo --noEmit --pretty false"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@elysiajs/eden": "^1.4.9",
|
|
17
|
+
"@sinclair/typebox": "^0.34.52",
|
|
18
|
+
"@tpl/db": "workspace:*",
|
|
19
|
+
"@tpl/shared": "workspace:*",
|
|
20
|
+
"better-auth": "catalog:",
|
|
21
|
+
"elysia": "catalog:",
|
|
22
|
+
"exact-mirror": "^1.2.7",
|
|
23
|
+
"file-type": "^22.3.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@cloudflare/workers-types": "catalog:",
|
|
27
|
+
"@typescript/native-preview": "catalog:",
|
|
28
|
+
"typescript": "catalog:"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { treaty } from "@elysiajs/eden"
|
|
2
|
+
import type { Api } from "./server"
|
|
3
|
+
|
|
4
|
+
export type { Api } from "./server"
|
|
5
|
+
|
|
6
|
+
export function createApiClient(baseUrl: string, fetcher?: typeof fetch) {
|
|
7
|
+
return treaty<Api>(baseUrl, {
|
|
8
|
+
fetch: { credentials: "include" },
|
|
9
|
+
...(fetcher ? { fetcher } : {}),
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TApiClient = ReturnType<typeof createApiClient>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare namespace Cloudflare {
|
|
2
|
+
interface Env {
|
|
3
|
+
DB: D1Database
|
|
4
|
+
MEDIA: R2Bucket
|
|
5
|
+
/** Cloudflare Email Service; never called while `ENVIRONMENT` is `local`. */
|
|
6
|
+
EMAIL: SendEmail
|
|
7
|
+
MESSAGES_RATE_LIMITER: RateLimit
|
|
8
|
+
/** Absent: the contact form and the sign-in skip the Turnstile check. */
|
|
9
|
+
TURNSTILE_SECRET_KEY?: string
|
|
10
|
+
BETTER_AUTH_SECRET: string
|
|
11
|
+
PUBLIC_SITE_URL: string
|
|
12
|
+
/** Better Auth's base URL, so its cookies and magic links live on the admin's origin. */
|
|
13
|
+
ADMIN_URL: string
|
|
14
|
+
/** `local` on a dev machine: mails go to the dev inbox and the dev routes exist. */
|
|
15
|
+
ENVIRONMENT: string
|
|
16
|
+
EMAIL_FROM: string
|
|
17
|
+
/** Comma-separated: the only addresses that receive a sign-in link. */
|
|
18
|
+
ADMIN_EMAILS: string
|
|
19
|
+
/** Empty outside production: server errors stay local. */
|
|
20
|
+
SENTRY_DSN?: string
|
|
21
|
+
/** Comma-separated DSNs the browser error tunnel may relay to. */
|
|
22
|
+
SENTRY_TUNNEL_DSNS?: string
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface CloudflareEnv extends Cloudflare.Env {}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const HTML_ESCAPES: Record<string, string> = {
|
|
2
|
+
"&": "&",
|
|
3
|
+
"<": "<",
|
|
4
|
+
">": ">",
|
|
5
|
+
'"': """,
|
|
6
|
+
"'": "'",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const HTML_SPECIAL_RE = /[&<>"']/g
|
|
10
|
+
|
|
11
|
+
export function escapeHtml(value: string): string {
|
|
12
|
+
return value.replace(HTML_SPECIAL_RE, (char) => HTML_ESCAPES[char] ?? char)
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// E-mail clients ignore stylesheets and CSS variables: inline neutral colours are the only option here.
|
|
2
|
+
export function emailLayout(title: string, content: string): string {
|
|
3
|
+
return `<!doctype html>
|
|
4
|
+
<html lang="fr">
|
|
5
|
+
<body style="margin:0;background:#f4f4f5;font-family:Helvetica,Arial,sans-serif;color:#18181b">
|
|
6
|
+
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="padding:40px 16px">
|
|
7
|
+
<tr>
|
|
8
|
+
<td align="center">
|
|
9
|
+
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:480px;background:#ffffff;border-radius:12px;padding:32px">
|
|
10
|
+
<tr>
|
|
11
|
+
<td>
|
|
12
|
+
<h1 style="margin:0 0 16px;font-size:22px">${title}</h1>
|
|
13
|
+
${content}
|
|
14
|
+
</td>
|
|
15
|
+
</tr>
|
|
16
|
+
</table>
|
|
17
|
+
</td>
|
|
18
|
+
</tr>
|
|
19
|
+
</table>
|
|
20
|
+
</body>
|
|
21
|
+
</html>`
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
2
|
+
import { escapeHtml } from "./escape-html"
|
|
3
|
+
import { emailLayout } from "./layout"
|
|
4
|
+
import type { OutgoingEmail } from "../lib/dev-tools-contract"
|
|
5
|
+
|
|
6
|
+
export function renderMagicLinkEmail({
|
|
7
|
+
to,
|
|
8
|
+
url,
|
|
9
|
+
expiresInMinutes,
|
|
10
|
+
}: {
|
|
11
|
+
to: string
|
|
12
|
+
url: string
|
|
13
|
+
expiresInMinutes: number
|
|
14
|
+
}): OutgoingEmail {
|
|
15
|
+
const subject = `Votre lien de connexion · ${PROJECT_TITLE}`
|
|
16
|
+
|
|
17
|
+
const html = emailLayout(
|
|
18
|
+
"Connexion au back office",
|
|
19
|
+
`<p style="margin:0 0 24px;color:#52525b;font-size:15px;line-height:1.6">Ce lien est valable ${expiresInMinutes} minutes et ne sert qu'une fois.</p>
|
|
20
|
+
<a href="${escapeHtml(url)}" style="display:inline-block;background:#18181b;color:#fafafa;text-decoration:none;font-weight:bold;font-size:15px;padding:14px 28px;border-radius:8px">Me connecter</a>
|
|
21
|
+
<p style="margin:24px 0 0;color:#71717a;font-size:12px;line-height:1.6">Vous n'avez rien demandé ? Ignorez ce message.</p>`
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const text = `Connexion au back office ${PROJECT_TITLE}
|
|
25
|
+
|
|
26
|
+
Ouvrez ce lien (valable ${expiresInMinutes} minutes, une seule fois) :
|
|
27
|
+
${url}
|
|
28
|
+
|
|
29
|
+
Vous n'avez rien demandé ? Ignorez ce message.`
|
|
30
|
+
|
|
31
|
+
return { to, subject, html, text }
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TMessageInput } from "@tpl/shared/messages"
|
|
2
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
3
|
+
import { escapeHtml } from "./escape-html"
|
|
4
|
+
import { emailLayout } from "./layout"
|
|
5
|
+
import type { OutgoingEmail } from "../lib/dev-tools-contract"
|
|
6
|
+
|
|
7
|
+
export function renderNewMessageEmail({
|
|
8
|
+
to,
|
|
9
|
+
message,
|
|
10
|
+
adminUrl,
|
|
11
|
+
}: {
|
|
12
|
+
to: string
|
|
13
|
+
message: Pick<TMessageInput, "name" | "email" | "body">
|
|
14
|
+
adminUrl: string
|
|
15
|
+
}): OutgoingEmail {
|
|
16
|
+
const subject = `Nouveau message de ${message.name} · ${PROJECT_TITLE}`
|
|
17
|
+
|
|
18
|
+
const html = emailLayout(
|
|
19
|
+
"Nouveau message",
|
|
20
|
+
`<p style="margin:0 0 8px;font-size:15px"><strong>${escapeHtml(message.name)}</strong> <${escapeHtml(message.email)}></p>
|
|
21
|
+
<p style="margin:0 0 24px;color:#52525b;font-size:15px;line-height:1.6;white-space:pre-line">${escapeHtml(message.body)}</p>
|
|
22
|
+
<a href="${escapeHtml(adminUrl)}" style="color:#18181b;font-size:14px">Ouvrir le back office</a>`
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const text = `Nouveau message de ${message.name} <${message.email}>
|
|
26
|
+
|
|
27
|
+
${message.body}
|
|
28
|
+
|
|
29
|
+
${adminUrl}`
|
|
30
|
+
|
|
31
|
+
return { to, subject, html, text }
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
2
|
+
import { env } from "../lib/context"
|
|
3
|
+
import { devInbox } from "../lib/dev-inbox"
|
|
4
|
+
import { bindingDeliver, createDevAwareSender } from "../lib/dev-inbox/send"
|
|
5
|
+
import { isLocalEnvironment } from "../lib/environment"
|
|
6
|
+
|
|
7
|
+
export const sendEmail = createDevAwareSender({
|
|
8
|
+
deliver: (email) =>
|
|
9
|
+
bindingDeliver(env.EMAIL, { email: env.EMAIL_FROM, name: PROJECT_TITLE })(
|
|
10
|
+
email
|
|
11
|
+
),
|
|
12
|
+
inbox: devInbox,
|
|
13
|
+
isLocal: isLocalEnvironment,
|
|
14
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Elysia } from "elysia"
|
|
2
|
+
import { auth } from "./auth"
|
|
3
|
+
|
|
4
|
+
export const authGuard = new Elysia({ name: "auth-guard" }).macro({
|
|
5
|
+
authenticated: {
|
|
6
|
+
async resolve({ status, request }) {
|
|
7
|
+
const session = await auth().api.getSession({ headers: request.headers })
|
|
8
|
+
|
|
9
|
+
if (!session) {
|
|
10
|
+
return status(401, { message: "Authentification requise." })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return { user: session.user }
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { PROJECT_TITLE } from "@tpl/shared/project"
|
|
2
|
+
import { betterAuth } from "better-auth"
|
|
3
|
+
import { prismaAdapter } from "better-auth/adapters/prisma"
|
|
4
|
+
import { APIError } from "better-auth/api"
|
|
5
|
+
import { captcha } from "better-auth/plugins/captcha"
|
|
6
|
+
import { magicLink } from "better-auth/plugins/magic-link"
|
|
7
|
+
import { renderMagicLinkEmail } from "../emails/magic-link"
|
|
8
|
+
import { sendEmail } from "../emails/send"
|
|
9
|
+
import { env, prisma } from "./context"
|
|
10
|
+
import { isAdminEmail } from "./environment"
|
|
11
|
+
|
|
12
|
+
export const AUTH_BASE_PATH = "/api/auth"
|
|
13
|
+
|
|
14
|
+
const MAGIC_LINK_EXPIRES_IN_SECONDS = 15 * 60
|
|
15
|
+
const SESSION_EXPIRES_IN_SECONDS = 30 * 24 * 60 * 60
|
|
16
|
+
|
|
17
|
+
/** D1 has no interactive transactions; hiding `$transaction` makes the adapter run its steps sequentially. */
|
|
18
|
+
function withoutInteractiveTransactions<T extends object>(client: T): T {
|
|
19
|
+
return new Proxy(client, {
|
|
20
|
+
get: (target, key) =>
|
|
21
|
+
key === "$transaction" ? undefined : Reflect.get(target, key),
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function signInCaptcha() {
|
|
26
|
+
if (!env.TURNSTILE_SECRET_KEY) {
|
|
27
|
+
return []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [
|
|
31
|
+
captcha({
|
|
32
|
+
provider: "cloudflare-turnstile",
|
|
33
|
+
secretKey: env.TURNSTILE_SECRET_KEY,
|
|
34
|
+
endpoints: ["/sign-in/magic-link"],
|
|
35
|
+
}),
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createAuth() {
|
|
40
|
+
return betterAuth({
|
|
41
|
+
appName: PROJECT_TITLE,
|
|
42
|
+
baseURL: env.ADMIN_URL,
|
|
43
|
+
basePath: AUTH_BASE_PATH,
|
|
44
|
+
secret: env.BETTER_AUTH_SECRET,
|
|
45
|
+
trustedOrigins: [env.ADMIN_URL],
|
|
46
|
+
advanced: { ipAddress: { ipAddressHeaders: ["cf-connecting-ip"] } },
|
|
47
|
+
database: prismaAdapter(withoutInteractiveTransactions(prisma), {
|
|
48
|
+
provider: "sqlite",
|
|
49
|
+
}),
|
|
50
|
+
plugins: [
|
|
51
|
+
...signInCaptcha(),
|
|
52
|
+
magicLink({
|
|
53
|
+
expiresIn: MAGIC_LINK_EXPIRES_IN_SECONDS,
|
|
54
|
+
storeToken: "hashed",
|
|
55
|
+
// The answer is the same for every address, so the form never reveals who is an admin.
|
|
56
|
+
async sendMagicLink({ email, url }) {
|
|
57
|
+
if (!isAdminEmail(email)) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await sendEmail(
|
|
62
|
+
renderMagicLinkEmail({
|
|
63
|
+
to: email,
|
|
64
|
+
url,
|
|
65
|
+
expiresInMinutes: MAGIC_LINK_EXPIRES_IN_SECONDS / 60,
|
|
66
|
+
})
|
|
67
|
+
)
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
],
|
|
71
|
+
session: {
|
|
72
|
+
expiresIn: SESSION_EXPIRES_IN_SECONDS,
|
|
73
|
+
cookieCache: { enabled: true, maxAge: 5 * 60 },
|
|
74
|
+
},
|
|
75
|
+
rateLimit: {
|
|
76
|
+
enabled: true,
|
|
77
|
+
customRules: {
|
|
78
|
+
"/get-session": false,
|
|
79
|
+
"/sign-in/magic-link": { window: 60, max: 3 },
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
databaseHooks: {
|
|
83
|
+
user: {
|
|
84
|
+
create: {
|
|
85
|
+
async before(user) {
|
|
86
|
+
if (!isAdminEmail(user.email)) {
|
|
87
|
+
throw new APIError("FORBIDDEN", {
|
|
88
|
+
message: "Cette adresse n'a pas accès au back office.",
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
data: { ...user, name: user.name || user.email.split("@")[0] },
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let instance: ReturnType<typeof createAuth> | undefined
|
|
103
|
+
|
|
104
|
+
export function auth() {
|
|
105
|
+
instance ??= createAuth()
|
|
106
|
+
|
|
107
|
+
return instance
|
|
108
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Elysia } from "elysia"
|
|
2
|
+
import type { DevInboxStore } from "./store"
|
|
3
|
+
import {
|
|
4
|
+
DEV_ROUTES,
|
|
5
|
+
type DevEnvironment,
|
|
6
|
+
type DevOk,
|
|
7
|
+
} from "../dev-tools-contract"
|
|
8
|
+
|
|
9
|
+
const HTML_ESCAPES: Record<string, string> = {
|
|
10
|
+
'"': """,
|
|
11
|
+
"&": "&",
|
|
12
|
+
"'": "'",
|
|
13
|
+
"<": "<",
|
|
14
|
+
">": ">",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function escapeHtml(text: string): string {
|
|
18
|
+
return text.replace(/[&<>"']/g, (char) => HTML_ESCAPES[char] ?? char)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DevRoutesOptions {
|
|
22
|
+
environment: () => DevEnvironment | Promise<DevEnvironment>
|
|
23
|
+
inbox: () => DevInboxStore | Promise<DevInboxStore>
|
|
24
|
+
/** True only when `ENVIRONMENT=local`; read per request so a deployed Worker never answers. */
|
|
25
|
+
isLocal: () => boolean
|
|
26
|
+
/** Mounted under the API's own prefix: "/dev" under "/api" gives "/api/dev". */
|
|
27
|
+
prefix?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const OK: DevOk = { ok: true }
|
|
31
|
+
|
|
32
|
+
/** The `/api/dev/*` routes the dev toolbar reads; outside local they do not exist, not even as a refusal. */
|
|
33
|
+
export function devRoutes({
|
|
34
|
+
environment,
|
|
35
|
+
inbox,
|
|
36
|
+
isLocal,
|
|
37
|
+
prefix = "/dev",
|
|
38
|
+
}: DevRoutesOptions) {
|
|
39
|
+
return new Elysia({ aot: false, name: "rc-dev-routes", prefix })
|
|
40
|
+
.onBeforeHandle(({ status }) => {
|
|
41
|
+
if (!isLocal()) {
|
|
42
|
+
return status(404, { message: "Not Found" })
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.get(DEV_ROUTES.environment, () => environment())
|
|
46
|
+
.get(DEV_ROUTES.inbox, async () => (await inbox()).list())
|
|
47
|
+
.delete(DEV_ROUTES.inbox, async () => {
|
|
48
|
+
await (await inbox()).clear()
|
|
49
|
+
|
|
50
|
+
return OK
|
|
51
|
+
})
|
|
52
|
+
.get("/inbox/:id", async ({ params, status }) => {
|
|
53
|
+
const message = await (await inbox()).read(params.id)
|
|
54
|
+
|
|
55
|
+
return message ?? status(404, { message: "Not Found" })
|
|
56
|
+
})
|
|
57
|
+
.get("/inbox/:id/html", async ({ params, status }) => {
|
|
58
|
+
const message = await (await inbox()).read(params.id)
|
|
59
|
+
|
|
60
|
+
if (!message) {
|
|
61
|
+
return status(404, "Not Found")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const html =
|
|
65
|
+
message.html ??
|
|
66
|
+
`<pre style="font-family:ui-monospace,monospace;white-space:pre-wrap;padding:1rem">${escapeHtml(message.text)}</pre>`
|
|
67
|
+
|
|
68
|
+
return new Response(html, {
|
|
69
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
.post("/inbox/:id/read", async ({ params }) => {
|
|
73
|
+
await (await inbox()).markRead(params.id)
|
|
74
|
+
|
|
75
|
+
return OK
|
|
76
|
+
})
|
|
77
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { DevInboxStore } from "./store"
|
|
2
|
+
import type { OutgoingEmail } from "../dev-tools-contract"
|
|
3
|
+
|
|
4
|
+
export type SendEmail = (email: OutgoingEmail) => Promise<void>
|
|
5
|
+
|
|
6
|
+
/** The slice of the Cloudflare Email Service binding (`send_email`) a sender needs. */
|
|
7
|
+
export interface EmailBinding {
|
|
8
|
+
send(message: {
|
|
9
|
+
from: { email: string; name: string }
|
|
10
|
+
html?: string
|
|
11
|
+
subject: string
|
|
12
|
+
text: string
|
|
13
|
+
to: string
|
|
14
|
+
}): Promise<unknown>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DevAwareSenderOptions {
|
|
18
|
+
/** Sends for real: usually `bindingDeliver(env.EMAIL, { email, name })`. */
|
|
19
|
+
deliver: SendEmail
|
|
20
|
+
inbox: () => DevInboxStore | Promise<DevInboxStore>
|
|
21
|
+
isLocal: () => boolean
|
|
22
|
+
log?: (line: string) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Locally nothing leaves the machine: each e-mail lands in the dev inbox (R2 `dev-inbox/`) and the log. */
|
|
26
|
+
export function createDevAwareSender({
|
|
27
|
+
deliver,
|
|
28
|
+
inbox,
|
|
29
|
+
isLocal,
|
|
30
|
+
log = console.info,
|
|
31
|
+
}: DevAwareSenderOptions): SendEmail {
|
|
32
|
+
return async (email) => {
|
|
33
|
+
if (isLocal()) {
|
|
34
|
+
await (await inbox()).record(email)
|
|
35
|
+
log(`[email] to=${email.to} subject="${email.subject}" → dev inbox`)
|
|
36
|
+
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await deliver(email)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function bindingDeliver(
|
|
45
|
+
binding: EmailBinding,
|
|
46
|
+
from: { email: string; name: string }
|
|
47
|
+
): SendEmail {
|
|
48
|
+
return async (email) => {
|
|
49
|
+
await binding.send({
|
|
50
|
+
from,
|
|
51
|
+
html: email.html,
|
|
52
|
+
subject: email.subject,
|
|
53
|
+
text: email.text,
|
|
54
|
+
to: email.to,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
}
|