diff --git a/AGENTS.md b/AGENTS.md index 30f842e..12a2b43 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,6 @@ app-admin/ # SvelteKit admin app (serves admin.) │ │ ├── items/ # Service/product CRUD (menu label: Services & products) │ │ ├── slots/ # Bookable slots: month calendar (?month=YYYY-MM), CRUD, bulk generate/copy/clear │ │ ├── orders/ # Order list + booking-email status/resend -│ │ ├── customers/ # Customer personal data (GDPR): search, export, correct, erase, retention settings │ │ ├── emails/ # Block-based booking email editor (live preview, test send) │ │ ├── globals/ # Header/footer/colors editor (menu label: Site design) │ │ ├── backup/ # Export/import UI (calls api/export, api/import) @@ -132,7 +131,6 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type - **Schema changes**: add a migration to `pocketbase/pb_migrations/` (runs once, on the next PocketBase start) **and** mirror it in `pb_schema.json` (fresh installs import that after the migrations have already run). Migrations must skip missing collections and must not throw for data problems — a failing migration stops PocketBase from starting. - **API rules**: CMS collections require `@request.auth.id != ''`, so `users` must never allow public sign-up (its createRule is superuser-only). Commerce writes (orders, order_lines, baskets, basket_lines) are superuser-only; they happen in the PocketBase shop hooks (`pocketbase/pb_hooks/shop/lib.js`), which bypass rules. - **Slot availability** (places + blocking by overlapping bookings, incl. get-ready time) is computed only by `slotStates()` in the shop hooks — the public listing, basket holds and the admin `/slots` page all go through it (`GET /api/shop/slots`, `?detail=1` for the admin). Never store booking state on a slot or re-implement the rule elsewhere; see the README's *Slot availability*. -- **Customer personal data (GDPR)** lives in `orders.customerDetails`/`email` and (during checkout) `baskets`. Admin access, correction, erasure (= anonymise the order, never delete it — the accounts need it) and the retention cron are in `pocketbase/pb_hooks/privacy/`; the admin `/customers` page only calls `/api/privacy/*`. A new place that stores customer details (e.g. a Google Calendar sync) must be covered by export, erase and retention too, and listed in the privacy draft (`app-admin/src/lib/admin/privacyTemplate.ts`). Don't load third-party resources on public pages (fonts are bundled; Stripe.js loads only at Pay) — each one sends visitors' IPs elsewhere and may need consent. See the README's *Personal data (GDPR)*. - **Shop / payments**: all basket, slot-hold, Stripe and order logic lives in the PocketBase hooks (JSVM: synchronous, each handler `require()`s the lib; see the header comment). The public app must stay unprivileged — no superuser login, no Stripe secret key; its routes only proxy to `/api/shop/*` and manage the `basket_id` cookie (`app-public/src/lib/server/shop.ts`). Booking emails are rendered and sent by the public app from data the webhook hook returns (`OrderEmailData`, `sendOrderEmailsFromData`); keep `orderEmailData()` in the hook and `loadOrderEmailData()` in `packages/shared/src/server/email` returning the same shape. Local testing uses `stripe-mock` (`STRIPE_API_BASE`, local compose only). ### Styling diff --git a/README.md b/README.md index 6784ea9..19a75e0 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Commerce collections (see the Stripe section above for context): - `slots` — `item` relation→items, `start` date, `end` date, `capacity` number (places; >1 = group session), `notes` text. Nothing about bookings is stored here — see *Slot availability* below - `baskets` — `status` select `active|completed|abandoned`, `expiresAt` date, `email` text, `customerDetails` json, `stripePaymentIntentId` text - `basket_lines` — `basket` relation→baskets, `item` relation→items, `slot` relation→slots (nullable), `quantity` number (places, for a slot line), `lineType` select `item|slot`, `heldUntil` date (a slot line's hold) -- `orders` — `basket` relation→baskets, `email` text, `customerDetails` json, `total` number, `status` select `pending|paid|refunded`, `stripePaymentIntentId` text, `customerEmailSentAt` date, `clientEmailSentAt` date, `emailError` text, `anonymisedAt` date (set by GDPR erasure/retention; `email` is then empty) +- `orders` — `basket` relation→baskets, `email` text, `customerDetails` json, `total` number, `status` select `pending|paid|refunded`, `stripePaymentIntentId` text, `customerEmailSentAt` date, `clientEmailSentAt` date, `emailError` text - `order_lines` — `order` relation→orders, `item` relation→items, `slot` relation→slots (nullable), `quantity` number, `lineType` select `item|slot`, `name` text (snapshot), `price` number (snapshot), `start` date (nullable, snapshot) - `email_templates` — `key` text (unique: `customer_confirmation` | `client_alert`), `subject` text, `blocks` json, `recipients` text, `enabled` bool @@ -140,7 +140,6 @@ All routes in `app-admin` except `/login` are guarded in `src/hooks.server.ts`. - `/items` — services and products shown in Shop blocks - `/slots` — bookable time slots: month calendar, single slots, and bulk tools — *Generate slots* (date range × weekdays × opening hours, spaced by the service's duration + get-ready time), *Copy a week* (repeat into the next 1–12 weeks) and *Clear slots* (slots with no places taken). Bulk tools preview first and skip slots in the past or overlapping a slot of the same service. Different services may share a time; whichever is booked first blocks the others (see *Slot availability*). The calendar marks slots available / in a basket / booked / full / blocked, with places taken for group sessions. - `/orders` — confirmed bookings and purchases, with booking-email status and resend buttons -- `/customers` — customer personal data (GDPR): search, export as JSON, correct details on every order, erase, and the data-retention settings (see *Personal data (GDPR)*) - `/emails` — block-based editor for the booking confirmation and new-booking alert emails (live preview, test send) - `/globals` — header/footer/colors editor @@ -190,18 +189,6 @@ Setup: With `SMTP_HOST` empty (local dev) emails are written to the app container logs instead of being sent. -## Personal data (GDPR) - -What the software does; the studio (the controller) is responsible for the privacy policy text and for how it uses the data. - -- **What is stored:** name, email, phone and booking notes, on `orders.customerDetails` (one copy per order) and on `baskets` while checkout is in progress. A paid basket's copy is cleared as soon as its order exists. -- **Privacy policy:** *Site design → Footer → Privacy policy page* links a page from the footer and above the Pay button. *Create a privacy policy draft* makes an unpublished `privacy` page describing what this software does, with [gaps] to fill in. -- **Checkout:** a short privacy notice with the link, and a hint under the notes field asking customers not to write health details (special-category data). There is deliberately no "I consent" box: booking data is processed to perform the contract, not on consent. Both texts are editable in the Checkout block. -- **Customers (admin):** look a customer up by name, email, phone or notes (orders and unpaid checkouts, matched by email case-insensitively); *Export data (JSON)* for access/portability requests; correct name/email/phone or remove notes on every record; *Erase* anonymises their orders (amounts, services and dates stay for the accounts) and deletes unpaid checkouts. Stripe and the email provider keep their own copies — handle those in their dashboards. -- **Retention:** daily at 03:15 UTC and on PocketBase start (`pocketbase/pb_hooks/privacy.pb.js`): unpaid checkouts are deleted after *N* days (default 30); orders are anonymised after *M* months (default 0 = never — set it once the accountant has said how long records must be kept). Orders with a booking still ahead are skipped. Settings live in the `privacy` global. -- **No third parties on page load:** fonts are bundled (`@fontsource/*`), not loaded from Google, and Stripe.js loads only when the customer presses Pay (`@stripe/stripe-js/pure`). The only cookies are the basket cookie and the admin login, so no cookie banner is needed — keep it that way, or add one before adding analytics. -- All customer-data reads and writes go through `/api/privacy/*` (signed-in admin only; `orders`/`baskets` are superuser-only collections). - ## Public routes (public app) - `/` renders `pages.slug = "home"` diff --git a/app-admin/package-lock.json b/app-admin/package-lock.json index d0e5f0e..85cdb4e 100644 --- a/app-admin/package-lock.json +++ b/app-admin/package-lock.json @@ -26,8 +26,6 @@ "uuid": "^14.0.0" }, "devDependencies": { - "@fontsource/dm-sans": "^5.3.0", - "@fontsource/playfair-display": "^5.3.0", "@sveltejs/kit": "^2.57.0", "@sveltejs/vite-plugin-svelte": "^7.0.0", "@types/node": "^25.8.0", @@ -120,26 +118,6 @@ "license": "MIT", "peer": true }, - "node_modules/@fontsource/dm-sans": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/@fontsource/dm-sans/-/dm-sans-5.3.0.tgz", - "integrity": "sha512-lYJtMXXO28q1z+yz+z8XKd0s4hXaa9QdkETzkyD760sidCv5heI86weYA0sx0Nc4pAMAQTUuyf4gO44cYKKS9g==", - "dev": true, - "license": "OFL-1.1", - "funding": { - "url": "https://github.com/sponsors/ayuhito" - } - }, - "node_modules/@fontsource/playfair-display": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/@fontsource/playfair-display/-/playfair-display-5.3.0.tgz", - "integrity": "sha512-uJSABalvdWc10fEPppQjQocamT21LEyRfzzWfRfqbkPz+sRv+kKpYDKyluBUskvJREkJTos9epj1WjQROGu99Q==", - "dev": true, - "license": "OFL-1.1", - "funding": { - "url": "https://github.com/sponsors/ayuhito" - } - }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", diff --git a/app-admin/package.json b/app-admin/package.json index 4d1be42..f2205ab 100644 --- a/app-admin/package.json +++ b/app-admin/package.json @@ -10,8 +10,6 @@ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" }, "devDependencies": { - "@fontsource/dm-sans": "^5.3.0", - "@fontsource/playfair-display": "^5.3.0", "@sveltejs/kit": "^2.57.0", "@sveltejs/vite-plugin-svelte": "^7.0.0", "@types/node": "^25.8.0", diff --git a/app-admin/src/app.css b/app-admin/src/app.css index 811e139..d0de454 100644 --- a/app-admin/src/app.css +++ b/app-admin/src/app.css @@ -1,3 +1,4 @@ +@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@600;700&display=swap'); @import 'tailwindcss'; @plugin 'daisyui' { themes: light --default; diff --git a/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte b/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte index ea92a03..a5874d1 100644 --- a/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte +++ b/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte @@ -1,5 +1,5 @@ - -Customers | CMS - -{#snippet message(show: boolean)} - {#if show && form?.message} -
{form.message}
- {/if} -{/snippet} - -
-
-

Customers

-

Personal data from bookings — look someone up to send them a copy, correct it or erase it (GDPR).

-
- -
-
-

Find a customer

- - - {#if data.customers.length === 0} -

{data.q ? 'No customer matches.' : 'No customers yet.'}

- {:else} - - {#if data.truncated} -

Showing customers from the newest orders only — search to narrow it down.

- {/if} - {/if} -
- -
- {#if !customer} -

Pick a customer to see everything stored about them.

- {:else if !hasRecords} -

{customer.email}

-

Nothing is stored for this email address.

- {@render message(true)} - {:else} -
-
-

{current.name || customer.email}

-

{customer.email}

-
- Export data (JSON) -
- -
- - - - - {#if hasNotes} - - {/if} -
- -
-
- {@render message(!form?.settings)} - -

Orders

-
    - {#each customer.orders as order (order.id)} -
  • -
    - {formatDateTime(order.created, data.timezone)} · {order.status} - {money.format(order.total)} -
    -
      - {#each order.lines as line} -
    • {line.quantity}× {line.name}{line.start ? ` — ${formatDateTime(line.start, data.timezone)}` : ''}
    • - {/each} -
    - {#if order.customerDetails.notes} -

    "{order.customerDetails.notes}"

    - {/if} -
  • - {/each} -
- - {#if customer.unpaidBaskets.length} -

Unpaid checkouts

-

Details typed at checkout without paying. Deleted automatically after {data.settings.abandonedBasketDays} days.

-
    - {#each customer.unpaidBaskets as basket (basket.id)} -
  • {formatDateTime(basket.updated, data.timezone)} — {basket.customerDetails.name || '(no name)'}{basket.customerDetails.phone ? ` · ${basket.customerDetails.phone}` : ''}
  • - {/each} -
- {/if} - -
-

Erase this customer

-

- For a request to be forgotten. Removes their name, email, phone and notes from every order (the amounts, services and dates stay, for your accounts) and deletes unpaid checkouts. - Their payment also exists in Stripe and their booking emails in your email provider's logs — handle those in those services. -

- {#if upcoming.length} -

They have {upcoming.length} upcoming booking{upcoming.length === 1 ? '' : 's'}.

- {/if} -
- - -
-
- {/if} -
-
- -
-

Data retention

-

Applied automatically every night. Check how long your accountant needs booking records before turning on anonymising.

-
- - -
- - {@render message(!!form?.settings)} -
-
diff --git a/app-admin/src/routes/customers/export/+server.ts b/app-admin/src/routes/customers/export/+server.ts deleted file mode 100644 index be0b7af..0000000 --- a/app-admin/src/routes/customers/export/+server.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { error } from '@sveltejs/kit'; -import { loadCustomer } from '$lib/server/customers'; -import type { RequestHandler } from './$types'; - -// A customer's data as a JSON file — what to send someone who asks for a -// copy of their data (GDPR access / portability). Auth-guarded like every -// admin route (hooks.server.ts). -export const GET: RequestHandler = async ({ locals, url }) => { - const email = url.searchParams.get('email')?.trim() ?? ''; - if (!email) error(400, 'Missing email'); - const data = await loadCustomer(locals.pb, email); - const name = email.replace(/[^a-z0-9@._-]+/gi, '_'); - return new Response(JSON.stringify(data, null, 2), { - headers: { - 'content-type': 'application/json; charset=utf-8', - 'content-disposition': `attachment; filename="customer-data-${name}.json"`, - 'cache-control': 'no-store' - } - }); -}; diff --git a/app-admin/src/routes/globals/+page.server.ts b/app-admin/src/routes/globals/+page.server.ts index 323fd33..957aa84 100644 --- a/app-admin/src/routes/globals/+page.server.ts +++ b/app-admin/src/routes/globals/+page.server.ts @@ -1,6 +1,5 @@ -import { fail, redirect } from '@sveltejs/kit'; +import { fail } from '@sveltejs/kit'; import { ClientResponseError } from 'pocketbase'; -import { PRIVACY_PAGE_SLUG, privacyTemplateHtml } from '$lib/admin/privacyTemplate'; import { attempt } from '$lib/server/actions'; import { defaultColors, defaultFooter, defaultHeader } from '$lib/types'; import type { Actions, PageServerLoad } from './$types'; @@ -52,19 +51,5 @@ export const actions: Actions = { const result = await attempt('Could not save.', () => locals.pb.collection('globals').update(id, { data: value })); if (!result.ok) return fail(400, { section, ok: false, message: result.failure.data.message }); return { section, ok: true, message: 'Saved.' }; - }, - - // An unpublished privacy policy page to fill in, opened in the page editor. - createPrivacyDraft: async ({ locals }) => { - const result = await attempt('Could not create the privacy policy draft.', () => - locals.pb.collection('pages').create({ - slug: PRIVACY_PAGE_SLUG, - title: 'Privacy policy', - published: false, - blocks: [{ id: crypto.randomUUID(), type: 'text', data: { content: privacyTemplateHtml } }] - }) - ); - if (!result.ok) return fail(400, { section: 'footer', ok: false, message: result.failure.data.message }); - redirect(303, `/pages/${PRIVACY_PAGE_SLUG}`); } }; diff --git a/app-admin/src/routes/globals/+page.svelte b/app-admin/src/routes/globals/+page.svelte index 3c5215a..8b093e3 100644 --- a/app-admin/src/routes/globals/+page.svelte +++ b/app-admin/src/routes/globals/+page.svelte @@ -1,7 +1,6 @@