feat(prod): Sprint Q — reminders J-1 + cleanup cron endpoints #91
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/karbe-sprint-q"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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êteAuthorization: Bearer ${CRON_TOKEN}. Le token est déjà dans.env.production.GET /api/cron/remindersstartDate ∈ [now+22h, now+26h](fenêtre 4h pour absorber les retards de cron)sendBookingReminder(carbet) ousendRentalReminder(rental, avec contact provider)cron.reminders.runGET /api/cron/cleanupcron.cleanup.run2 nouveaux emails
sendBookingReminder— rappel J-1 séjour carbet avec CTA réservation + détails carbetsendRentalReminder— 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 à 9hGET /api/cron/cleanup— 1× par semaineTest plan
GET /api/cron/reminderssans token → 401GET /api/cron/cleanup→ JSON {invitesDeleted, bookingsCancelled, ...}cron.*.run🤖 Generated with Claude Code
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>