Aller au contenu
login
arrow_backRetour aux issues
moizycodes/moizy-open-source-issues #168

🚨 Issue: Add Idempotency-Key Support for API Operations

ecoDébutant help wanted testing backend javascript api dev-experience real-world

descriptionDescription

## ⚠️ IMPORTANT CONTRIBUTION RULE **Create a NEW branch before starting.** - ❌ Do not work on `main` - ❌ Do not create the PR from `main` - ❌ PRs from `main` will **NOT be accepted** Required format: ``` git checkout -b your-username/issue-97 ``` ## 📌 Real-World Problem Network failures can cause clients to retry the same request. For operations such as creating an order or processing a payment, this can accidentally create **duplicate records or duplicate actions**. An idempotency key allows the server to recognize that multiple requests belong to the same operation. ## 🎯 Task Create a dependency-free utility for generating and validating idempotency keys. Example: ``` const key = createIdempotencyKey(); ``` Expected: ``` idempotency_7f3c91a2... ``` Also provide: ``` isValidIdempotencyKey(key); ``` which returns `true` or `false`. ## 🔧 Requirements - Generate sufficiently unique keys - Validate key format - Reject empty or malformed keys - Keep the API simple - Do not expose sensitive request data inside the key - Add comprehensive unit tests - Include practical API usage documentation ## 🌍 Why This Matters Idempotency is important for real-world systems handling: - Payments - Orders - Account creation - Booking systems - Subscription management - Background jobs - External API requests A network retry should not **accidentally perform the same operation twice**. ## 🧪 Tests Should Cover - Generated key is valid - Multiple generated keys are different - Empty values - Invalid formats - Very long keys - Non-string input - Repeated API requests using the same key ## ✅ Acceptance Criteria - Utility generates unique idempotency keys - Validation works consistently - No request-sensitive information is encoded - Comprehensive tests are included - Documentation contains a real API example - No unnecessary dependencies - Existing functionality remains unchanged - PR comes from a **new username/issue-number branch**
codeOuvre sur GitHub