Repository navigation
Read Amazon report files on the server and add finance tools - #1645
Merged
Merged
Conversation
A REST tool can now follow a download link in its response (endpointMapping.download): fetched server-side through fetchOutbound (SSRF-guarded, no credentials, size caps), gunzipped, parsed as TSV/CSV/JSON and returned one page at a time. amazon_seller_download_report_document uses it. Add amazon_seller_list_transactions, amazon_seller_get_finance_summary and amazon_seller_list_service_fee_events, since listFinancialEvents has no event-type filter. The OpenAPI importer now reads Swagger 2.0 'in: body' parameters. Tools imported from Swagger 2.0 specs (Amazon SP-API) sent no body and no Content-Type, which Amazon answers with 400.
helpcodeai
enabled auto-merge (squash)
November 12, 2026 09:02
Contributor
Author
|
Security pass (daily check): OK to ship. The link is https only, on the allowed hosts, fetched with fetchOutbound (SSRF on every hop), with no connector credentials and byte and gunzip caps.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Starter customer on the Amazon Seller Central connector asked for three things: a way to read report files (the AI client cannot open the pre-signed S3 link that
amazon_get_report_documentreturns, and the file is often gzip), a way to look at one kind of financial event or at totals per fee type, and why some calls failed. This PR covers all three.endpointMapping.downloadblock on REST tools: the tool makes its API call as usual, then fetches the link in the response on the server, decompresses gzip, parses TSV/CSV/JSON and returns one page of rows (with paging, a column filter and column selection). The newamazon_seller_download_report_documenttool uses it.listFinancialEvents, so instead of a filter there are three tools:amazon_seller_list_transactions(Finances 2024-06-19, filter by date, status, order or settlement),amazon_seller_get_finance_summary(totals per charge type for a period or settlement) andamazon_seller_list_service_fee_events(only the ServiceFeeEventList, through a JMESPath transform).in: body. The importer only read OpenAPI 3requestBody, so tools imported from a Swagger 2.0 spec (all Amazon SP-API models, among others) had no body parameters and sent no body and no Content-Type. Amazon then answered400 Content type must be set to application/json(seen ongeneratePlacementOptions). The importer now maps the body schema intobodyMappingand its required fields. A required body whose schema has no fields of its own getsbodyTemplate: "{}".Changes
connectors/engines/download-follow.util.ts(new): fetch viafetchOutbound(SSRF checks on the link and every redirect, no connector credentials, 25 MB cap, 60 s timeout), https only,allowedHostsrequired, gunzip withmaxOutputLength64 MB (gzip-bomb safe), charset from Content-Type (Amazon uses Cp1252 for some reports), TSV and RFC 4180 CSV, page size default 50 and max 500.rest.engine.ts: when a mapping hasdownload, run the API call without it, then hand the body tofollowDownload. Tools without the block take exactly the old path.engine-types.ts:downloadonRestEndpointMapping.parsers/openapi.parser.ts: Swagger 2.0in: bodyparameters;{}body for a required body without fields.adapters/intl/amazon-seller.json: 4 new tools (amazon_seller_*prefix), descriptions ofamazon_get_report_documentandamazon_list_financial_eventspoint to them, instructions gain the new step 3 and a Finances section.adapters/catalog.spec.ts: arguments read bydownloadcount as used.docs/tool-definition.md: new section "Download links in the response (download)".Cloud and self-hosted behave the same. No new environment variable, no schema change, nothing under
ee/.Type
Testing
New specs:
download-follow.util.spec.ts(gzip by marker and by magic bytes, paging, filter with several values, column selection, error messages that list the columns, page cap, JSON, Cp1252, https and host checks includingamazonaws.com.evil.example, gzip bomb),rest.engine.download.spec.ts(the API call carries the connector's key, the link fetch does not; tools without the block are unchanged), Swagger 2.0 cases inopenapi.parser.spec.ts, and a static assertion inamazon-seller.live.spec.ts.Commands, in
packages/backendunless noted:npx jest --maxWorkers=4 src/connectors/engines src/connectors/parsers src/adapters/intl/amazon-seller.live.spec.ts: 63 suites passed (1 skipped live suite), 1148 tests passed.npx jest --maxWorkers=4 src/adapters/catalog.spec.ts: 15 904 passed.npx eslinton the changed files: clean.node scripts/validate-adapters.mjs --warn: 748 passed, 0 failed. The 15 warnings on amazon-seller are the existingtool-prefixones on the originalamazon_*names; the new tools add none.node scripts/regenerate-catalog.mjs: no diff.node scripts/adapter-count.mjs --check: OK.npx jest --maxWorkers=4): 31 871 passed. Failures are environmental, none in touched code. 68 suites failed to compile because this checkout's sharednode_moduleslacks@types/picomatch,@aws-sdk/client-s3andbasic-ftp(they are inpackage.json). 14 tests injwt-or-management-key.guard.spec.tsneed a local Postgres.tsc --noEmitshows only those same missing-module errors. CI runs on a clean install and is the reference.Not tested against live Amazon (no seller credentials here).
Checklist
npm test): see the note under TestingRelated Issues
Support request (Libredesk #268).