getSalesSummary CSV drops the name column when the top group is unnamed

Open Beginner friendly
#106 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, data

Research direction

The bug is in toCsv in src/tools/getSalesSummary.ts, which takes its column set from Object.keys(rows[0]) only. Start there, then read the group mapping that adds the name key conditionally. Add a test in src/tools/tests/sales.test.ts where only a lower-ranked row has a name, and confirm it yields a name column with an empty cell for the unnamed row. Run npm test.

Written by the indexing model from the issue text.

Description

bug good first issue priority: low

Summary

steam_getSalesSummary with format: "csv" takes its columns from the first row only. When the top group has no name but later groups do, the name column is left out of the whole CSV.

Where

  • src/tools/getSalesSummary.ts (toCsv: const cols = Object.keys(rows[0]);)
  • src/tools/getSalesSummary.ts (group mapping: ...(name ? { name } : {}))

Details

function toCsv(rows: Array<Record<string, unknown>>): string {
  if (rows.length === 0) return "";
  const cols = Object.keys(rows[0]);
  ...
}

Each group only gets a name key when app_info, package_info, or country_info named it. Rows are sorted by net revenue, so whether the CSV has a name column depends on whether the top earner happened to be named. If row 0 is named and others are not, those get an empty cell, which is fine; the reverse loses every name.

Impact

Low. Steam normally returns names for the countries, apps, and packages on the page, so this needs an unnamed group at the top. When it happens, a spreadsheet export silently drops the names column.

Steps to reproduce

  1. Stub GetDetailedSales so the top-revenue row's country_code has no country_info entry and a smaller row's does.
  2. Call steam_getSalesSummary { start_date, format: "csv" }.
  3. The header has no name column.

Suggested fix

Build cols as the union of keys across all rows, in first-seen order, or always set name (empty string when unknown) so every row has the same keys.

Acceptance criteria

  • A test where only a lower row is named produces a name column with that name and an empty cell for the unnamed row.

Getting started

  • Relevant files: src/tools/getSalesSummary.ts, src/tools/__tests__/sales.test.ts
  • How to run tests: npm test

Filed by repo-audit/fix-issues at a23ec21. Severity: low. Effort: S. audit-key: bug|src/tools/getSalesSummary.ts|toCsv

Dominant language
TypeScript
Stars
5
Forks
2
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TMHSDigital/steam-mcp

All issues in TMHSDigital/steam-mcp

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.