Shop: move commerce logic into PocketBase hooks; public app unprivileged

The public (internet-facing) app logged in as the PocketBase superuser and
held the Stripe secret key, so any bug in it could become full control of
the database. Baskets, slot holds, Stripe PaymentIntents, the webhook that
creates orders, and the payment-result lookup now run in PocketBase JS
hooks (pocketbase/pb_hooks/shop, routes under /api/shop/*, plus a cron
that releases expired holds every minute).

The public app's routes keep their URLs but only proxy to those routes and
manage the basket cookie; it has no PocketBase or Stripe secret. Booking
emails are still rendered and sent by the public app (same renderer as the
admin preview) from order data the webhook hook returns; it records the
outcome via a narrow endpoint guarded by INTERNAL_API_SECRET.

Also: slot add and order creation are now transactional; shop listings
load anonymously (already public via API rules); shop API errors always
reach the browser as JSON; the superuser client and stripe package are
removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
agent 2026-10-06 12:34:58 +00:00
parent 1f929c68ca
commit 773fecc090
14 changed files with 914 additions and 507 deletions

View file

@ -13,6 +13,15 @@ services:
- pocketbase:/pb_data
# Versioned schema changes; PocketBase applies pending ones on start.
- ./pocketbase/pb_migrations:/pb_migrations:ro,Z
# Shop API (baskets, slot holds, Stripe payments, orders) — the only
# place commerce data is written. See pocketbase/pb_hooks/shop/lib.js.
- ./pocketbase/pb_hooks:/pb_hooks:ro,Z
environment:
STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY:-}
STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET:-}
STRIPE_CURRENCY: ${STRIPE_CURRENCY:-eur}
# Shared with app-public: lets it record booking-email status on orders.
INTERNAL_API_SECRET: ${INTERNAL_API_SECRET:-}
app-admin:
build:
@ -29,9 +38,6 @@ services:
ORIGIN: http://admin.${DOMAIN:-localhost}:8080
PUBLIC_SITE_URL: http://www.${DOMAIN:-localhost}:8080
BODY_SIZE_LIMIT: 52428800 # 50MB — import payload embeds all images as base64
# Commerce (reservation & payment system) — set these in a root-level .env
POCKETBASE_ADMIN_EMAIL: ${POCKETBASE_ADMIN_EMAIL:-}
POCKETBASE_ADMIN_PASSWORD: ${POCKETBASE_ADMIN_PASSWORD:-}
STRIPE_CURRENCY: ${STRIPE_CURRENCY:-eur}
# Booking emails (Brevo SMTP relay) — admin needs these for resend/test sends
SMTP_HOST: ${SMTP_HOST:-}
@ -58,13 +64,11 @@ services:
POCKETBASE_INTERNAL_URL: http://pocketbase:80
PUBLIC_POCKETBASE_URL: http://db.${DOMAIN:-localhost}:8080
ORIGIN: http://www.${DOMAIN:-localhost}:8080
# Commerce (reservation & payment system) — set these in a root-level .env
POCKETBASE_ADMIN_EMAIL: ${POCKETBASE_ADMIN_EMAIL:-}
POCKETBASE_ADMIN_PASSWORD: ${POCKETBASE_ADMIN_PASSWORD:-}
STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY:-}
STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET:-}
# No PocketBase or Stripe secrets here: shop writes happen in PocketBase
# (pb_hooks/shop). The publishable key is public by design.
PUBLIC_STRIPE_PUBLISHABLE_KEY: ${PUBLIC_STRIPE_PUBLISHABLE_KEY:-}
STRIPE_CURRENCY: ${STRIPE_CURRENCY:-eur}
INTERNAL_API_SECRET: ${INTERNAL_API_SECRET:-}
# Booking emails (Brevo SMTP relay) — sent from the Stripe webhook
SMTP_HOST: ${SMTP_HOST:-}
SMTP_PORT: ${SMTP_PORT:-587}