feat: refactor template engine, webhook dispatcher, and subscription state machine (closes #584, #585, #586)#630
Conversation
…state machine (closes Smartdevs17#584, Smartdevs17#585, Smartdevs17#586) Smartdevs17#584 - AST-based template engine - Lexer + Parser: tokenize template string, produce AST (Text, Variable, If, For, Filter, Partial nodes) - Compiler: AST -> JS render function with Map-based LRU cache (max 100 entries) - Filters: uppercase, lowercase, date format (multiple presets), currency (locale-aware), pluralize - Partials: reusable template fragments with parameter passing - Sandbox: prevent infinite loops (max 100 iterations), deep recursion (max 10 depth) - Malformed template -> friendly error with line number and expected token - EmailTemplateService refactored to use new engine Smartdevs17#585 - Webhook dispatcher as separate horizontally-scalable service - services/webhook-dispatcher/ with package.json, tsconfig, Dockerfile - Events enqueued to Redis Stream from main API (producer), dispatcher consumes (consumer group) - Dispatcher workers: configurable concurrency (default 10, max 50) - Dedicated dispatcher PostgreSQL schema for delivery logs and retry state - Health check endpoint: GET /health returns queue depth, active workers, error rate, uptime - Graceful shutdown: SIGTERM waits for in-flight deliveries (max 30s) - docker-compose.yml with dispatcher, Redis, PostgreSQL services - CI pipeline (.github/workflows/webhook-dispatcher-ci.yml) - K8s HPA config (CPU >70% -> scale up) Smartdevs17#586 - Hierarchical state chart for subscription state machine - State hierarchy: Active (Trial, Paid, PastDue), Inactive (Cancelled, Paused at end of cycle, Expired), Suspended (FraudHold, AdminHold) - Transition guards for each edge (canCancel, canPause, canResume, etc.) - Entry/exit actions: configurable side effects (send email, stop billing, revoke access) - State history: ordered list of transitions with actor, timestamp, reason - Mermaid state diagram generator from machine definition - Exhaustive transition matrix tests - Invalid transition returns error with list of valid transitions
|
@Junman140 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 15742864 | Triggered | Generic Password | daf674f | docker-compose.yml | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Summary
This PR implements three major refactors specified in issues #584, #585, and #586.
#584 - AST-based Template Engine
Replaces regex-based string interpolation with a full AST-based template engine:
#585 - Webhook Dispatcher Service
Extracts webhook delivery from main API process into standalone service:
#586 - Hierarchical State Chart
Flat enum replaced with hierarchical state chart:
Closes #584, closes #585, closes #586