트랜잭션을위한 API 경로를 작성하려고하는데, 나는 braintree 서버에서 트랜잭션 세부 사항을 가져오고 싶습니다.브레인 트리가있는 Nodej 스트림?
내 앱이 내 앱 사용자의 ID와 동일한 지 확인합니다. customerId()
그래서 아래에 로그인 한 특정 사용자에 대한 모든 거래를 검색합니다.
의미 req.user.id
은 항상 braintree 서버에있는 customerId()
과 같습니다.
app.get('/project', function(req, res) {
if(req.user) {
// Finds all transactions for a particular customer
var stream = gateway.transaction.search(function (search) {
search.customerId().is(req.user.id);
});
console.log(stream);
//res.send(stream);
}
});
세부 정보를 반환하고 싶지만 스트림은 아래처럼 보입니다. 그래서 분명히 이것은 노드 스트림을 처리하는 특정 방법이 있다고 생각하게합니까?
readable-stream
과 같은 것을 보았습니다.이 스트림 객체를 처리해야하는지 확실하지 않습니다.
제 질문은 어떻게 트랜잭션의 세부 정보를 반환하도록 스트림 객체를 처리합니까?
{ _readableState:
{ highWaterMark: 16384,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: false,
ended: false,
endEmitted: false,
reading: false,
calledRead: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
objectMode: true,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: {},
_maxListeners: 10,
searchResponse: { stream: [Circular], success: true },
currentItem: 0,
currentOffset: 0,
bufferedResults: [] }
그래, 나중에 알게되었지만, 스트림 이벤트에서 데이터 오브젝트를 가져올 수있는 방법에 대해서는 약간 분실했습니다. 내가 사용하는 것에 대해 전혀 생각하지 않은 기본적인 바닐라 JS. 전의. var objects = []이면 스트림 데이터 이벤트에서 객체를 객체 배열로 푸시 한 다음 끝에 클라이언트에 보냅니다. –
이 라이브러리를 본 적이 없는지 https://github.com/rvagg/through2 - 스트림 조작에 매우 편리합니다. –
몫을 가져 주셔서 감사합니다. 나는 그 라이브러리를 사용하지 않아서 사용하기가 매우 쉽습니다. –