Skip to content

feat: Accept array-style Idempotency-Key headers on interactive deposit requests#159

Merged
0xNgoo merged 13 commits into0xNgoo:mainfrom
Belzabeem:feature/array-idempotency-headers
Apr 1, 2026
Merged

feat: Accept array-style Idempotency-Key headers on interactive deposit requests#159
0xNgoo merged 13 commits into0xNgoo:mainfrom
Belzabeem:feature/array-idempotency-headers

Conversation

@Belzabeem
Copy link
Copy Markdown
Contributor

Closes #94

The deposit route reads the idempotency header as a single string, but some frameworks can surface headers as arrays. This PR updates the deposit route so it can accept a non-empty Idempotency-Key value from either a string or a string array.

Changes

1. Updated src/runtime/http/express-router.ts

  • Added import: import { IdempotencyUtils } from '@/utils/idempotency.ts';
  • Changed idempotency key extraction:
    // Before:
    const idempotencyKey = req.headers['idempotency-key'];
    if (typeof idempotencyKey === 'string' && idempotencyKey.length > 0) {
    
    // After:
    const idempotencyKey = IdempotencyUtils.extractIdempotencyHeader(req.headers, 'idempotency-key');
    if (idempotencyKey !== null) {

2. Added focused tests in tests/utils/idempotency.test.ts

Added 5 new test cases:

  • extractIdempotencyHeader handles lowercase idempotency-key header name
  • extractIdempotencyHeader handles array idempotency-key with first non-empty value
  • extractIdempotencyHeader handles array idempotency-key with leading empty strings
  • extractIdempotencyHeader handles array idempotency-key with only empty values

Test Results

  • All 181 tests pass (the 5 failing tests are pre-existing SQLite issues unrelated to this change)
  • Both string and string-array header shapes now work for idempotent deposit requests

Acceptance Criteria

  • String and string-array header shapes both work for idempotent deposit requests
  • The existing conflict behavior for mismatched request bodies remains unchanged
  • Added focused tests for array-style idempotency headers
  • Run bun test before opening the pull request

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 25, 2026

@Belzabeem 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! 🚀

Learn more about application limits

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the deposit route by allowing it to correctly interpret the Idempotency-Key header when it's presented as an array of strings, a common behavior in some web frameworks. The change centralizes the header extraction logic into a dedicated utility, making the system more resilient to varying input formats and improving the overall reliability of idempotent operations.

Highlights

  • Idempotency Header Handling: The deposit route now correctly processes Idempotency-Key headers that are provided as an array of strings, in addition to single string values. This addresses scenarios where frameworks might surface headers as arrays.
  • Refactored Idempotency Key Extraction: The logic for extracting the idempotency key has been centralized into IdempotencyUtils.extractIdempotencyHeader, improving code reusability and maintainability.
  • Enhanced Test Coverage: New focused tests were added for IdempotencyUtils.extractIdempotencyHeader to ensure robust handling of various header formats, including lowercase header names and array-style values with different combinations of empty and non-empty strings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the idempotency key extraction in express-router.ts by introducing and utilizing IdempotencyUtils.extractIdempotencyHeader. This change also simplifies the idempotency key check from a type and length check to a null check. The review suggests applying this simplified check consistently to other relevant lines in the express-router.ts file. Additionally, new tests were added for the IdempotencyUtils, but some of them appear to be redundant with existing tests and could be removed to improve test suite maintainability.

@0xNgoo
Copy link
Copy Markdown
Owner

0xNgoo commented Mar 26, 2026

@Belzabeem Please fix CI

@0xNgoo
Copy link
Copy Markdown
Owner

0xNgoo commented Mar 27, 2026

Hey @Belzabeem

Please fix CI and conflict

0xNgoo and others added 11 commits March 28, 2026 10:22
Exercise cleanupOldRecords with a cutoff timestamp: expired auth,
idempotency, processed webhooks, and processed watcher rows are
removed; non-eligible rows remain.

Made-with: Cursor

Co-authored-by: AI Assistant <test@example.com>
0xNgoo#190)

* feat: implement configuration validation for database providers and URL formats with enhanced schema exports

* fix ci

* fix ci

---------

Co-authored-by: augustine00z <cofoedum@gmail.com>
0xNgoo#189)

* feat: implement AnchorConfig manager and ValidationUtils for SDK configuration and data sanitization

* fix ci

* Update validation.ts

* feat: add validation utilities with tests, implement CI workflow, and update tsconfig include paths

* fix ci

---------

Co-authored-by: augustine00z <cofoedum@gmail.com>
Co-authored-by: Paulie <113470324+0xNgoo@users.noreply.github.com>
@Belzabeem
Copy link
Copy Markdown
Contributor Author

I have fixed the CI and the conflicts

@0xNgoo 0xNgoo merged commit 168fab6 into 0xNgoo:main Apr 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accept array-style Idempotency-Key headers on interactive deposit requests

8 participants