Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
stream-amazon-sp-api
Advanced tools
Readme
download()
methodAfter short discussion in https://github.com/amz-tools/amazon-sp-api/issues/56 here is the code that stream the download of a file, sparing memory and resource for large report files coming from amazon
Streaming upload is disabled because it is still untested. It will be enabled by default as soon it get tested.
Streaming for upload is enabled from v1.0.5, it has no option, it just stream out over http from content
or from file
.
Streaming for upload: uploadStream() from v1.0.6 there is a new method uploadStream()
, I did not tested all feeds API. For AES case the Content-Length is calculated as ((origLen div 16) + 2) * 16
, but not tested.
Some credits goes to @stefanmaric for defer() staff used in request-stream-PUT version.
NOTE: breaking change the option returns
became returnType
.
let spApi = require('stream-amazon-sp-api');
let SellingPartner = spApi(options);
then try to use download:
try {
let reportDocument = await SellingPartner.callAPI({
operation:'getReportDocument',
endpoint:'reports',
path:{
reportDocumentId
}
});
let targetFile = "/your/absolute/path/filename.json";
await SellingPartner.download(reportDocument, {
//charset:'cp1252',
json: true,
returnType: 'none', // 'none' ,'string', or 'stream'
file: targetFile
});
} catch (err) {
console.log("ERROR", err);
}
// check targetFile content
}
upload example (feeds API):
let feedDocument = await spApi.callAPI({
operation:'createFeedDocument',
endpoint: "feeds",
body: {
"contentType": feedInfos.contentType
},
options: {
version: "2021-06-30"
}
})
// simply upload the document. Use spApi for convenience
let feed = {
"file": feedInfos.filename,
"contentType": feedInfos.contentType,
}
// new method! use .upload() if it does not work
let response = await spApi.uploadStream(feedDocument, feed);
// it is {success:true}
let res = await spApi.callAPI({
operation:'createFeed',
endpoint: "feeds",
body: {
marketplaceIds: ["MARKETID"],
feedType: feedInfos.feedType,
inputFeedDocumentId: feedDocument.feedDocumentId
}
});
return res;
Note that this is the only case I really tested.
returnType:stream
and json:true
are "partially compatible options": when used together and upstream document content-type is an xml, then this patch will throw Error.
Note that most of the time amazon compress xml, and that xml content-type is taken from http headers, and so I am not really sure the code works.
Anyway it is better not to transform xml-to-json large files, or adopt some clever strategy (see section below).
If returnType:none
and no file:filename
was specified, the patched method will return undefined, after doing nothing, I can suppose that errors also are not detected, in fact stream are opened, piped, but no writable is passed to it.
It add dependency to
nonexml-to-json-stream
module, that support stream as transformer.
request-stream.js
is just for GET request, then upload request should have an out version.
csvtojson is more clever than one would expect, see https://github.com/Keyang/node-csvtojson/blob/master/src/Result.ts In fact it adds a '[' at begin then it parse line by line adding a regular json for each line, separated by commas. So, it really stream the content.
as commented in upstream issue report, I found this in StackOverflow https://stackoverflow.com/a/52562921/250970 and https://www.npmjs.com/package/xml-flow https://www.npmjs.com/package/xml-stream so https://www.npmjs.com/package/xtreamer
The example in xtreamer is simple enough to be used with returnType:stream
FAQs
Streamable version of download by monkey patching. Only for testing/development purpose
The npm package stream-amazon-sp-api receives a total of 2 weekly downloads. As such, stream-amazon-sp-api popularity was classified as not popular.
We found that stream-amazon-sp-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.