Skip to content

Send the partner's mapping list ranges when creating an account template - #274

Open
michieldegezelle wants to merge 1 commit into
mainfrom
fix-partner-mapping-ranges-on-create
Open

michieldegezelle wants to merge 1 commit into
mainfrom
fix-partner-mapping-ranges-on-create

Conversation

@michieldegezelle

Copy link
Copy Markdown
Contributor

Problem

silverfin create-account-template -p <partner-id> never sent the partner's mapping_list_ranges. newAccountTemplate filtered them with a hardcoded range.type === "firm":

template.mapping_list_ranges = template.mapping_list_ranges.filter((range) => {
  return range.type === "firm" && range.env_id === envId;
});

On a partner that predicate matches nothing, so the create payload always carried mapping_list_ranges: []. The template arrived on the partner with only its base account_range and no mapping list association.

The follow-up update-account-template then had to add the range rather than update it, which the API rejects:

422: {"error":"Not allowed to add range for mapping list 2"}

Templates that already existed on the partner were never affected — their range already exists, so the update is an update. That's the create/update split reported from the field.

Both sibling functions, publishAccountTemplateByName and publishAccountTemplateById, already filter on type. This brings the create path in line. The hardcoded "firm" dates back to #158 (Support create commands) and was never covered by a test — every existing newAccountTemplate test passes "firm" with empty ranges.

Changes

index.js, newAccountTemplate:

  1. range.type === "firm" → range.type === type — the fix.
  2. Guard the filter with ?. / || [], matching the two update paths. A config.json without a mapping_list_ranges key threw a TypeError.
  3. Check response.status before reading response.data. sfApi returns undefined for a 400/404 (apiUtils.responseErrorHandler bare-returns on both), so a failed create died with Cannot read properties of undefined instead of surfacing the API error.

(2) and (3) are pre-existing, but a partner create can now realistically be rejected by the API — and (3) in particular would have masked that rejection behind an opaque TypeError, which is exactly the diagnosis this change is meant to enable.

Tests

Four new tests in tests/lib/toolkit.test.js, each written failing first:

  • partner create keeps that partner's ranges, dropping other partners' and firms'
  • firm create still keeps only that firm's ranges (regression guard)
  • a config with no mapping_list_ranges key sends [] rather than throwing
  • an undefined API response reports a failure rather than crashing

621/621 pass, ESLint clean.

Note on scope

This makes the CLI send the partner ranges at create time; it does not prove the API accepts them there. If a partner create still returns a 422, the remaining question is genuinely server-side — whether marketplace package assignment is a prerequisite for associating a new partner template with a mapping list. Change (3) means that answer will now be legible instead of a TypeError.

Deliberately left out, all pre-existing and none specific to the partner path: the env_id strict string-vs-number comparison (affects all three call sites identically), newAllAccountTemplates' lack of error containment (unreachable for partners — checkPartnerSupport rejects --all with -p), extracting the now-thrice-duplicated filter into AccountTemplate, and the missing version_significant_change on partner create.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 3ba0cd67-1b76-4468-9174-10c89262bb6c

📥 Commits

Reviewing files that changed from the base of the PR and between e6b5645 and 4013c56.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • CHANGELOG.md
  • index.js
  • package.json
  • tests/TESTS.md
  • tests/lib/toolkit.test.js

Included review availability: 3 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.

📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (1)
Run `npm run lint && npm test` after code changes.

📄 CodeRabbit inference engine (CLAUDE.md)

Files:

  • package.json
  • index.js
  • tests/lib/toolkit.test.js
  • tests/TESTS.md
  • CHANGELOG.md
🔇 Additional comments (5)
index.js (1)

759-762: LGTM!

Also applies to: 767-772

tests/lib/toolkit.test.js (1)

925-952: LGTM!

Also applies to: 954-974, 976-985, 987-998

tests/TESTS.md (1)

1062-1065: LGTM!

CHANGELOG.md (1)

5-8: LGTM!

package.json (1)

3-3: LGTM!


Walkthrough

Changes

Account template creation

Layer / File(s) Summary
Creation behavior
index.js
newAccountTemplate filters mapping_list_ranges by entity type and environment. Missing ranges default to []. The function stores the template ID only when the response has status 201 and response data.
Creation validation and release update
tests/lib/toolkit.test.js, tests/TESTS.md, CHANGELOG.md, package.json
Tests cover partner and firm filtering, missing ranges, and undefined API responses. The package version changes to 1.60.1, and the changelog records the fixes.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Merge Risk: ⚪ Minimal · up to 4013c

The account-template creation change is ready to merge; the tested filtering and failed-response paths have no remaining concrete issue.

🚥 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (3 skipped: 3 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: sending partner mapping list ranges during account-template creation.
Description check ✅ Passed The description provides a detailed problem statement, implementation summary, test coverage, test results, and scope notes. It does not use the template headings or include the issue link and author/…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (3 skipped: 3 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-partner-mapping-ranges-on-create

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

`newAccountTemplate` hardcoded `range.type === "firm"` when filtering
`mapping_list_ranges` down to the target environment, so
`create-account-template -p <partner-id>` always sent an empty array. A
template created on a partner therefore arrived with only its base
`account_range` and no mapping list association at all.

The follow-up `update-account-template` then had to *add* the range rather
than update it, which the API rejects with
`422 Not allowed to add range for mapping list <id>`. Templates that already
existed on the partner were unaffected, since their range was an update.

Both sibling functions (`publishAccountTemplateByName`,
`publishAccountTemplateById`) already filter on `type`; this brings the
create path in line.

Also hardens the same function, since a partner create can now realistically
be rejected by the API:

- Guard the filter with `?.` / `|| []`, matching the two update paths. A
  config.json without a `mapping_list_ranges` key threw a TypeError.
- Check `response.status` before reading `response.data`. `sfApi` returns
  undefined for a 400/404, so a failed create crashed with "Cannot read
  properties of undefined" instead of surfacing the API error.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@michieldegezelle
michieldegezelle force-pushed the fix-partner-mapping-ranges-on-create branch from eb24deb to 4013c56 Compare September 16, 2026 14:33
@michieldegezelle michieldegezelle self-assigned this Sep 21, 2026
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.

1 participant