Skip to content

Implement card BIN functionality#29

Merged
gmorales96 merged 3 commits into
masterfrom
feature/add-card-bins-lookup
May 11, 2026
Merged

Implement card BIN functionality#29
gmorales96 merged 3 commits into
masterfrom
feature/add-card-bins-lookup

Conversation

@julietteceb16

@julietteceb16 julietteceb16 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Bank-name lookup now accepts card numbers (BIN-based) in addition to CLABE; a strict variant throws on invalid or unknown values.
    • A public card-BIN lookup table is now exposed.
  • Tests

    • Expanded tests for card/BIN lookups, CLABE lookups, edge cases, and error conditions.
  • Chores

    • Package version bumped to 1.4.0.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Walkthrough

This pull request extends bank name lookup to accept CLABE (18 digits) or card numbers (15–16 digits). It adds a CARD_BINS lookup table, updates TypeScript declarations, implements getBankName routing (ABM for CLABE, BIN for cards), updates getBankNameOrThrow, expands tests for card/BIN paths and error cases, and bumps the package version.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature added: card BIN (Bank Identification Number) lookup functionality, which is the primary change across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/add-card-bins-lookup

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/test.js`:
- Line 21: The test constant VALID_CARD_BBVA is currently a Luhn-valid PAN
('4152314501669421'); change its value to a clearly synthetic PAN that preserves
the BIN prefix 415231 but cannot pass Luhn (e.g., replace the trailing digits
with zeros) so tests still validate BIN logic but do not use a real-looking card
number — update the constant named VALID_CARD_BBVA accordingly in test/test.js.
- Line 5: Remove the unused CARD_BINS import from the destructured import list
in test/test.js (CARD_BINS is causing ESLint no-unused-vars); locate the import
statement that includes CARD_BINS and delete that identifier, or alternatively
add a minimal smoke test that references CARD_BINS (e.g., asserting it is
defined) so the symbol is used — update the import or add the test accordingly
to satisfy the linter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 20f3bd2f-383d-4ad5-ae5f-225665a646fb

📥 Commits

Reviewing files that changed from the base of the PR and between 24ad15a and 09b537f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • lib/card_bins.js
  • lib/index.d.ts
  • lib/index.js
  • test/test.js

Comment thread test/test.js Outdated
Comment thread test/test.js Outdated
@julietteceb16 julietteceb16 force-pushed the feature/add-card-bins-lookup branch from 09b537f to 07db5cb Compare May 8, 2026 00:16
Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
test/test.js (1)

20-20: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

VALID_CARD_BBVA is still a Luhn-valid PAN — replace the suffix with zeros.

'4152314501669421' passes the Luhn check and is flagged with confidence 1.0 by two independent analyzers (OpenGrep + Microsoft Presidio). Since the BIN prefix 415231 is the only meaningful part for these tests, replace the account-specific digits with zeros to make it unambiguously synthetic.

🐛 Proposed fix
-const VALID_CARD_BBVA = '4152314501669421'; // BIN 415231 -> 40012 -> BBVA Mexico
+const VALID_CARD_BBVA = '4152310000000000'; // BIN 415231 -> 40012 -> BBVA Mexico
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/test.js` at line 20, Replace the Luhn-valid PAN string in
VALID_CARD_BBVA so the test uses a synthetic, non-Luhn account portion: update
the constant VALID_CARD_BBVA (currently '4152314501669421') to keep the BIN
prefix '415231' and set the remaining account digits to zeros (e.g.,
'4152310000000000' or similar length-preserving zero suffix) so analyzers no
longer flag it as a real card number.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@test/test.js`:
- Line 20: Replace the Luhn-valid PAN string in VALID_CARD_BBVA so the test uses
a synthetic, non-Luhn account portion: update the constant VALID_CARD_BBVA
(currently '4152314501669421') to keep the BIN prefix '415231' and set the
remaining account digits to zeros (e.g., '4152310000000000' or similar
length-preserving zero suffix) so analyzers no longer flag it as a real card
number.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a1667a73-68d5-4a2f-a262-d1d5101ff0d8

📥 Commits

Reviewing files that changed from the base of the PR and between 09b537f and 07db5cb.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • lib/card_bins.js
  • lib/index.d.ts
  • lib/index.js
  • test/test.js
✅ Files skipped from review due to trivial changes (1)
  • lib/card_bins.js

Comment thread lib/index.js Outdated
Comment thread package.json Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/index.js`:
- Around line 49-53: The current checks only verify CLABE length and prefix when
resolving bank names; update both lookup sites (the block using
account.substring(0, 3) and the similar branch around lines 74-81) to validate
the full 18-digit CLABE using the official CLABE control-digit algorithm before
performing the ABM/bank-name lookup. Implement or call a helper like
validateClabe(account) that computes and verifies the control digit (using the
standard weights and modulus 10 rule) and only proceed to derive code =
account.substring(0,3) and BANK_NAMES[BANKS[code]] if validateClabe returns
true; otherwise return null (or the existing invalid-input response) to preserve
the contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c68135a0-f187-465a-9616-658b209a3aab

📥 Commits

Reviewing files that changed from the base of the PR and between d95b83f and 18f1027.

📒 Files selected for processing (4)
  • lib/index.d.ts
  • lib/index.js
  • package.json
  • test/test.js
✅ Files skipped from review due to trivial changes (1)
  • package.json

Comment thread lib/index.js
Comment on lines +49 to +53
if (account.length === CLABE_LENGTH) {
const code = account.substring(0, 3);
const bankName = BANK_NAMES[BANKS[code]];
return bankName === undefined ? null : bankName;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate full CLABE before ABM lookup in both APIs.

On Line 49 and Line 74, the 18-char path only checks length and prefix, so invalid CLABEs (including wrong control digit) can still resolve to a bank name. That breaks the documented invalid-input contract.

🐛 Proposed fix
 function getBankName(account) {
@@
   if (account.length === CLABE_LENGTH) {
+    if (!validateClabe(account)) return null;
     const code = account.substring(0, 3);
     const bankName = BANK_NAMES[BANKS[code]];
     return bankName === undefined ? null : bankName;
   }

   if (account.length >= 15 && account.length <= 16) {
+    if (!isANumber(account)) return null;
     const bin = account.substring(0, 6);
     const bankName = BANK_NAMES[CARD_BINS[bin]];
     return bankName === undefined ? null : bankName;
   }
@@
 function getBankNameOrThrow(account) {
@@
   if (account.length === CLABE_LENGTH) {
+    if (!validateClabe(account)) {
+      throw new Error('Cuenta inválida: CLABE no válida');
+    }
     const code = account.substring(0, 3);
     const bankName = BANK_NAMES[BANKS[code]];
@@
   if (account.length >= 15 && account.length <= 16) {
+    if (!isANumber(account)) {
+      throw new Error('Cuenta inválida: tarjeta debe contener solo dígitos');
+    }
     const bin = account.substring(0, 6);
     const bankName = BANK_NAMES[CARD_BINS[bin]];

Also applies to: 74-81

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/index.js` around lines 49 - 53, The current checks only verify CLABE
length and prefix when resolving bank names; update both lookup sites (the block
using account.substring(0, 3) and the similar branch around lines 74-81) to
validate the full 18-digit CLABE using the official CLABE control-digit
algorithm before performing the ABM/bank-name lookup. Implement or call a helper
like validateClabe(account) that computes and verifies the control digit (using
the standard weights and modulus 10 rule) and only proceed to derive code =
account.substring(0,3) and BANK_NAMES[BANKS[code]] if validateClabe returns
true; otherwise return null (or the existing invalid-input response) to preserve
the contract.

@gmorales96 gmorales96 merged commit 3509331 into master May 11, 2026
9 checks 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.

2 participants