feat(prod): Sprint Q — reminders J-1 + cleanup cron endpoints #91

Merged
tarzzan merged 1 commit from feat/karbe-sprint-q into main 2026-06-03 03:24:31 +00:00
Owner

Sprint Q — Reminders J-1 + cleanup cron endpoints

Endpoints automatisables par cron externe (Hermes, GitHub Actions ou crontab système) pour gérer les tâches récurrentes de la plateforme.

src/lib/cron-auth.ts (NEW)

isAuthorizedCronRequest(req) vérifie l'en-tête Authorization: Bearer ${CRON_TOKEN}. Le token est déjà dans .env.production.

GET /api/cron/reminders

  • Itère bookings carbet CONFIRMED + rentalBookings CONFIRMED dont startDate ∈ [now+22h, now+26h] (fenêtre 4h pour absorber les retards de cron)
  • Envoie sendBookingReminder (carbet) ou sendRentalReminder (rental, avec contact provider)
  • Compte sent/errors par type
  • Audit log cron.reminders.run
  • Retourne JSON détaillé

GET /api/cron/cleanup

  • Purge OrgInviteToken expirés depuis > 30j
  • Booking PENDING + paymentStatus≠SUCCEEDED + createdAt > 7j → CANCELLED + FAILED
  • RentalBooking idem + delete RentalItemAvailability associée (libère stock) en transaction
  • Audit log cron.cleanup.run

2 nouveaux emails

  • sendBookingReminder — rappel J-1 séjour carbet avec CTA réservation + détails carbet
  • sendRentalReminder — rappel J-1 récup matériel avec contacts provider (phone + email)

Tests vitest

tests/lib/cron-auth.test.ts (6 cas) : refus si CRON_TOKEN absent / header absent / format incorrect (Basic/Token) / token mismatch ; accept si match exact ou avec espaces.

Total : 89/89 ✓ (83 précédents + 6 nouveaux).

Schedule recommandé

À brancher côté Hermes ou crontab système :

  • GET /api/cron/reminders — 1× par jour à 9h
  • GET /api/cron/cleanup — 1× par semaine
curl -H "Authorization: Bearer $CRON_TOKEN" https://karbe.cosmolan.fr/api/cron/reminders

Test plan

  • Vitest 89/89 ✓
  • GET /api/cron/reminders sans token → 401
  • Avec token correct → 200 + JSON candidates/sent (vide si pas de booking J+1)
  • GET /api/cron/cleanup → JSON {invitesDeleted, bookingsCancelled, ...}
  • Audit log montre les 2 events cron.*.run

🤖 Generated with Claude Code

## Sprint Q — Reminders J-1 + cleanup cron endpoints Endpoints automatisables par cron externe (Hermes, GitHub Actions ou crontab système) pour gérer les tâches récurrentes de la plateforme. ### `src/lib/cron-auth.ts` (NEW) `isAuthorizedCronRequest(req)` vérifie l'en-tête `Authorization: Bearer ${CRON_TOKEN}`. Le token est déjà dans `.env.production`. ### `GET /api/cron/reminders` - Itère bookings carbet CONFIRMED + rentalBookings CONFIRMED dont `startDate ∈ [now+22h, now+26h]` (fenêtre 4h pour absorber les retards de cron) - Envoie `sendBookingReminder` (carbet) ou `sendRentalReminder` (rental, avec contact provider) - Compte sent/errors par type - Audit log `cron.reminders.run` - Retourne JSON détaillé ### `GET /api/cron/cleanup` - Purge OrgInviteToken expirés depuis > 30j - Booking PENDING + paymentStatus≠SUCCEEDED + createdAt > 7j → CANCELLED + FAILED - RentalBooking idem + delete RentalItemAvailability associée (libère stock) en transaction - Audit log `cron.cleanup.run` ### 2 nouveaux emails - `sendBookingReminder` — rappel J-1 séjour carbet avec CTA réservation + détails carbet - `sendRentalReminder` — rappel J-1 récup matériel avec contacts provider (phone + email) ### Tests vitest `tests/lib/cron-auth.test.ts` (6 cas) : refus si CRON_TOKEN absent / header absent / format incorrect (Basic/Token) / token mismatch ; accept si match exact ou avec espaces. **Total : 89/89 ✓** (83 précédents + 6 nouveaux). ### Schedule recommandé À brancher côté Hermes ou crontab système : - `GET /api/cron/reminders` — 1× par jour à 9h - `GET /api/cron/cleanup` — 1× par semaine ```bash curl -H "Authorization: Bearer $CRON_TOKEN" https://karbe.cosmolan.fr/api/cron/reminders ``` ### Test plan - [x] Vitest 89/89 ✓ - [ ] `GET /api/cron/reminders` sans token → 401 - [ ] Avec token correct → 200 + JSON candidates/sent (vide si pas de booking J+1) - [ ] `GET /api/cron/cleanup` → JSON {invitesDeleted, bookingsCancelled, ...} - [ ] Audit log montre les 2 events `cron.*.run` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tarzzan added 1 commit 2026-06-03 03:24:30 +00:00
feat(prod): Sprint Q — reminders J-1 + cleanup cron endpoints
All checks were successful
CI / test (pull_request) Successful in 2m45s
a6ea488732
Endpoints automatisables par cron externe (Hermes, GitHub Actions,
ou crontab système) pour gérer les tâches récurrentes de la
plateforme.

src/lib/cron-auth.ts (NEW) : isAuthorizedCronRequest(req) vérifie
l'en-tête Authorization Bearer ${CRON_TOKEN}. Le token est déjà dans
.env.production.

GET /api/cron/reminders :
- Itère bookings carbet CONFIRMED + rentalBookings CONFIRMED dont
  startDate ∈ [now+22h, now+26h] (fenêtre 4h pour absorber les
  éventuels retards de cron).
- Envoie sendBookingReminder (carbet) ou sendRentalReminder (rental).
- Compte bookingSent/bookingErrors et rentalSent/rentalErrors.
- Audit log scope=cron event=cron.reminders.run avec stats.
- Retourne JSON {ok, window, booking:{candidates,sent,errors},
  rental:{candidates,sent,errors}}.

GET /api/cron/cleanup :
- Purge OrgInviteToken expirés depuis > 30j.
- Booking PENDING + paymentStatus≠SUCCEEDED + createdAt > 7j →
  status=CANCELLED + paymentStatus=FAILED (libère le créneau).
- RentalBooking idem + delete RentalItemAvailability associée
  (libère stock) en transaction.
- Audit log scope=cron event=cron.cleanup.run avec compteurs.

src/lib/email.ts :
- sendBookingReminder(to, firstName, bookingId, title, startDate,
  slug) : email rappel J-1 avec CTA vers /reservations/[id].
- sendRentalReminder(to, firstName, rbId, providerName, startDate,
  contactInfo) : rappel pour récup matériel, affiche contacts
  provider (phone + email).

tests/lib/cron-auth.test.ts (6 cas) :
- Refus si CRON_TOKEN absent, header absent, format incorrect (Basic
  ou Token), token mismatch.
- Accept si match exact, accept avec espaces autour du token (defensive).

Total tests : 89/89 ✓.

Schedule recommandé (à brancher côté Hermes ou crontab) :
- GET /api/cron/reminders : 1× par jour à 9h (Authorization: Bearer
  $CRON_TOKEN)
- GET /api/cron/cleanup : 1× par semaine

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tarzzan merged commit 5845a6b950 into main 2026-06-03 03:24:31 +00:00
tarzzan deleted branch feat/karbe-sprint-q 2026-06-03 03:24:31 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: tarzzan/karbe#91
No description provided.