Le check-in remplace l'intégration banking V1 (cf. CLAUDE.md → Glossaire) :
avant que la 1re relance ne parte, on demande à l'user "as-tu été payé ?"
via email, et il clique sur l'un des 2 liens publics.
Service checkin_token.ts : génération + hash SHA-256. 32 bytes random base64url, plain dans le mail, hash en DB (CheckinTask.token_hash unique).
Service checkin_scheduler.ts :
- scheduleCheckinForInvoice(invoice) : crée 1 CheckinTask à dueDate (now+1min si dueDate dans le passé). Idempotent par invoice — cancel les scheduled précédents avant.
- cancelCheckinForInvoice(invoiceId) : appelé par mark-paid pour stopper.
Job send_checkin_job.ts : worker queue 'checkins', skip si invoice paid/cancelled (no-op), construit l'URL avec le plain token (passé dans le payload du job, pas relu DB), appelle sendCheckinEmail.
mail_dispatcher.ts : sendCheckinEmail() — texte brut, destinataire = user (pas client !), 2 URLs (paid / pending), TTL 24h annoncé.
Controller CheckinController :
- GET /api/v1/checkin/:token/paid : status=answered + answer=paid + mark invoice paid (mêmes effets que POST /invoices/:id/mark-paid : rubis +1, ActivityEvent invoice_paid avec label "via check-in", cancelFutureRelances). Idempotent : 2e click → redirect "already_answered".
- GET /api/v1/checkin/:token/pending : status=answered + answer=still_pending. Les relances suivent leur cours.
- Validation : lookup hash, expiry (sentAt + 24h), redirects propres pour invalid / expired / already_answered.
Routes : nouveau group public `checkin` (PAS de middleware.auth) à côté du group auth, sous /api/v1.
Triggers branchés :
- InvoicesController.store et ImportBatchesController.validateDraft → scheduleCheckinForInvoice après création
- InvoicesController.markPaid → cancelCheckinForInvoice dans la tx
start/queue.ts : registerWorker('checkins', sendCheckinJob).
env : nouveau WEB_URL (URL du SPA pour redirects), default localhost:5173 en dev.
Bruno : nouveau dossier 08-Checkin avec doc complète du flow + 2 requêtes (paid / pending). var d'env `checkinToken` à remplir manuellement après avoir reçu l'email dans Mailpit.
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
/*
|
|
|--------------------------------------------------------------------------
|
|
| Environment variables service
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| The `Env.create` method creates an instance of the Env service. The
|
|
| service validates the environment variables and also cast values
|
|
| to JavaScript data types.
|
|
|
|
|
*/
|
|
|
|
import { Env } from '@adonisjs/core/env'
|
|
|
|
export default await Env.create(new URL('../', import.meta.url), {
|
|
// Node
|
|
NODE_ENV: Env.schema.enum(['development', 'production', 'test'] as const),
|
|
PORT: Env.schema.number(),
|
|
HOST: Env.schema.string({ format: 'host' }),
|
|
LOG_LEVEL: Env.schema.string(),
|
|
|
|
// App
|
|
APP_KEY: Env.schema.secret(),
|
|
APP_URL: Env.schema.string({ format: 'url', tld: false }),
|
|
|
|
// Session
|
|
SESSION_DRIVER: Env.schema.enum(['cookie', 'memory', 'database'] as const),
|
|
|
|
// Database
|
|
DB_CONNECTION: Env.schema.enum.optional(['postgres', 'sqlite'] as const),
|
|
PG_HOST: Env.schema.string.optional({ format: 'host' }),
|
|
PG_PORT: Env.schema.number.optional(),
|
|
PG_USER: Env.schema.string.optional(),
|
|
PG_PASSWORD: Env.schema.string.optional(),
|
|
PG_DB_NAME: Env.schema.string.optional(),
|
|
|
|
// Redis (BullMQ + cache)
|
|
REDIS_HOST: Env.schema.string.optional({ format: 'host' }),
|
|
REDIS_PORT: Env.schema.number.optional(),
|
|
REDIS_PASSWORD: Env.schema.string.optional(),
|
|
|
|
// Storage (MinIO via S3 driver)
|
|
DRIVE_DISK: Env.schema.enum.optional(['s3', 'fs'] as const),
|
|
S3_ENDPOINT: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
S3_REGION: Env.schema.string.optional(),
|
|
S3_BUCKET: Env.schema.string.optional(),
|
|
S3_ACCESS_KEY: Env.schema.string.optional(),
|
|
S3_SECRET_KEY: Env.schema.string.optional(),
|
|
S3_FORCE_PATH_STYLE: Env.schema.boolean.optional(),
|
|
|
|
// Mail
|
|
MAIL_FROM_ADDRESS: Env.schema.string.optional(),
|
|
MAIL_FROM_NAME: Env.schema.string.optional(),
|
|
MAIL_DRIVER: Env.schema.enum.optional(['smtp', 'resend'] as const),
|
|
SMTP_HOST: Env.schema.string.optional({ format: 'host' }),
|
|
SMTP_PORT: Env.schema.number.optional(),
|
|
RESEND_API_KEY: Env.schema.string.optional(),
|
|
|
|
// OCR
|
|
OCR_PROVIDER: Env.schema.enum.optional(['mock', 'mistral'] as const),
|
|
MISTRAL_API_KEY: Env.schema.string.optional(),
|
|
|
|
// Web (URL du SPA pour redirects post-checkin)
|
|
WEB_URL: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
|
|
// Auth
|
|
ACCESS_TOKEN_TTL_MINUTES: Env.schema.number.optional(),
|
|
REFRESH_TOKEN_TTL_DAYS: Env.schema.number.optional(),
|
|
COOKIE_DOMAIN: Env.schema.string.optional(),
|
|
COOKIE_SECURE: Env.schema.boolean.optional(),
|
|
|
|
/*
|
|
|----------------------------------------------------------
|
|
| Variables for configuring the limiter package
|
|
|----------------------------------------------------------
|
|
*/
|
|
LIMITER_STORE: Env.schema.enum(['redis', 'memory'] as const)
|
|
})
|