balena-request
Advanced tools
Comparing version 13.3.2 to 13.3.3-build-updates-2698e0be2a764268831bf2388c82fabeeac542a4-1
@@ -249,13 +249,4 @@ "use strict"; | ||
// If status code is an error code, interpret the body of the request as an error. | ||
const chunks = []; | ||
download.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
yield new Promise((resolve, reject) => { | ||
download.on('error', reject); | ||
download.on('close', resolve); | ||
download.on('end', resolve); | ||
download.on('done', resolve); | ||
}); | ||
const responseError = chunks.join() || 'The request was unsuccessful'; | ||
const data = yield utils.getStreamContents(download); | ||
const responseError = data || 'The request was unsuccessful'; | ||
debugRequest(options, download.response); | ||
@@ -262,0 +253,0 @@ // @ts-expect-error error without request options |
import type BalenaAuth from 'balena-auth'; | ||
import type { BalenaRequestOptions, BalenaRequestResponse } from './request'; | ||
import { Readable } from 'stream'; | ||
/** | ||
@@ -150,1 +151,9 @@ * @module utils | ||
export declare function getRequestAsync($fetch?: typeof fetch): (options: BalenaRequestOptions) => Promise<BalenaRequestResponse<any>>; | ||
/** | ||
* @summary A function that returns the contents of a stream | ||
* @function | ||
* @protected | ||
* | ||
* @param {Readable} [stream] - the stream to get the contents of | ||
*/ | ||
export declare function getStreamContents(stream: Readable): Promise<string>; |
@@ -28,2 +28,3 @@ "use strict"; | ||
exports.getRequestAsync = getRequestAsync; | ||
exports.getStreamContents = getStreamContents; | ||
const tslib_1 = require("tslib"); | ||
@@ -481,1 +482,23 @@ const { fetch: normalFetch, Headers: HeadersPonyfill } = | ||
} | ||
/** | ||
* @summary A function that returns the contents of a stream | ||
* @function | ||
* @protected | ||
* | ||
* @param {Readable} [stream] - the stream to get the contents of | ||
*/ | ||
function getStreamContents(stream) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const chunks = []; | ||
stream.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
yield new Promise((resolve, reject) => { | ||
stream.on('error', reject); | ||
stream.on('close', resolve); | ||
stream.on('end', resolve); | ||
stream.on('done', resolve); | ||
}); | ||
return chunks.join(); | ||
}); | ||
} |
@@ -7,2 +7,9 @@ # Change Log | ||
## 13.3.3 - 2024-12-03 | ||
* Tests: add missing @types/temp dependency [Pagan Gazzard] | ||
* Tests: remove bluebird dependency [Pagan Gazzard] | ||
* Tests: remove rindle dependency [Pagan Gazzard] | ||
* Update `author` in package.json [Pagan Gazzard] | ||
## 13.3.2 - 2024-07-12 | ||
@@ -9,0 +16,0 @@ |
@@ -367,13 +367,4 @@ /* | ||
// If status code is an error code, interpret the body of the request as an error. | ||
const chunks: unknown[] = []; | ||
download.on('data', function (chunk: unknown) { | ||
chunks.push(chunk); | ||
}); | ||
await new Promise((resolve, reject) => { | ||
download.on('error', reject); | ||
download.on('close', resolve); | ||
download.on('end', resolve); | ||
download.on('done', resolve); | ||
}); | ||
const responseError = chunks.join() || 'The request was unsuccessful'; | ||
const data = await utils.getStreamContents(download); | ||
const responseError = data || 'The request was unsuccessful'; | ||
@@ -380,0 +371,0 @@ debugRequest(options, download.response); |
@@ -547,1 +547,22 @@ /* | ||
} | ||
/** | ||
* @summary A function that returns the contents of a stream | ||
* @function | ||
* @protected | ||
* | ||
* @param {Readable} [stream] - the stream to get the contents of | ||
*/ | ||
export async function getStreamContents(stream: Readable) { | ||
const chunks: unknown[] = []; | ||
stream.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
await new Promise((resolve, reject) => { | ||
stream.on('error', reject); | ||
stream.on('close', resolve); | ||
stream.on('end', resolve); | ||
stream.on('done', resolve); | ||
}); | ||
return chunks.join(); | ||
} |
{ | ||
"name": "balena-request", | ||
"version": "13.3.2", | ||
"version": "13.3.3-build-updates-2698e0be2a764268831bf2388c82fabeeac542a4-1", | ||
"description": "Balena HTTP client", | ||
@@ -35,3 +35,3 @@ "main": "build/request.js", | ||
}, | ||
"author": "Juan Cruz Viotti <juanchiviotti@gmail.com>", | ||
"author": "Balena Ltd. <hello@balena.io>", | ||
"license": "Apache-2.0", | ||
@@ -47,6 +47,6 @@ "devDependencies": { | ||
"@types/sinon": "^10.0.11", | ||
"@types/temp": "^0.9.4", | ||
"assert": "^2.0.0", | ||
"balena-auth": "^6.0.1", | ||
"balena-config-karma": "4.0.0", | ||
"bluebird": "^3.7.2", | ||
"browserify-zlib": "^0.2.0", | ||
@@ -62,5 +62,5 @@ "buffer": "^5.7.1", | ||
"querystring-es3": "^0.2.1", | ||
"rindle": "^1.3.6", | ||
"sinon": "^15.0.1", | ||
"stream-browserify": "^3.0.0", | ||
"string-to-stream": "^3.0.1", | ||
"temp": "^0.8.4", | ||
@@ -88,4 +88,4 @@ "timekeeper": "^1.0.0", | ||
"versionist": { | ||
"publishedAt": "2024-07-12T08:40:04.114Z" | ||
"publishedAt": "2024-12-03T15:16:48.906Z" | ||
} | ||
} |
import { expect } from 'chai'; | ||
import setup from './setup'; | ||
import * as rindle from 'rindle'; | ||
import * as sinon from 'sinon'; | ||
@@ -96,3 +95,3 @@ import * as mockhttp from 'mockttp'; | ||
); | ||
return rindle.extract(stream); | ||
return utils.getStreamContents(stream); | ||
}))); | ||
@@ -145,3 +144,3 @@ }); | ||
); | ||
return rindle.extract(stream); | ||
return utils.getStreamContents(stream); | ||
})); | ||
@@ -162,3 +161,3 @@ | ||
); | ||
return rindle.extract(stream); | ||
return utils.getStreamContents(stream); | ||
})); | ||
@@ -197,3 +196,3 @@ }); | ||
expect(stream.response.request.uri.query).to.not.exist; | ||
return rindle.extract(stream); | ||
return utils.getStreamContents(stream); | ||
}))); | ||
@@ -200,0 +199,0 @@ })); |
import { expect } from 'chai'; | ||
import setup from './setup'; | ||
import * as Bluebird from 'bluebird'; | ||
import * as rindle from 'rindle'; | ||
import * as stringToStream from 'string-to-stream'; | ||
import * as sinon from 'sinon'; | ||
@@ -11,3 +10,3 @@ import * as mockhttp from 'mockttp'; | ||
const { auth, request } = setup(); | ||
const { auth, request, delay } = setup(); | ||
@@ -62,3 +61,3 @@ describe('An interceptor', function () { | ||
request(req) { | ||
return Bluebird.delay(100).then(() => | ||
return delay(100).then(() => | ||
Object.assign({}, req, { url: mockServer.urlFor('/changed') }), | ||
@@ -107,3 +106,3 @@ ); | ||
}) | ||
.then(rindle.extract) | ||
.then(utils.getStreamContents) | ||
.then(function (data) { | ||
@@ -262,3 +261,3 @@ const body = JSON.parse(data); | ||
response(response) { | ||
return Bluebird.delay(100).then(() => | ||
return delay(100).then(() => | ||
Object.assign({}, response, { body: { replaced: true } }), | ||
@@ -302,3 +301,3 @@ ); | ||
response() { | ||
return rindle.getStreamFromString('replacement stream'); | ||
return stringToStream('replacement stream'); | ||
}, | ||
@@ -311,3 +310,3 @@ }; | ||
}) | ||
.then(rindle.extract) | ||
.then(utils.getStreamContents) | ||
.then((data) => expect(data).to.equal('replacement stream')); | ||
@@ -314,0 +313,0 @@ }); |
@@ -9,10 +9,4 @@ import * as errors from 'balena-errors'; | ||
const { auth, request, getCustomRequest, IS_BROWSER } = setup(); | ||
const { auth, request, getCustomRequest, IS_BROWSER, delay } = setup(); | ||
// Grab setTimeout before we replace it with a fake later, so | ||
// we can still do real waiting in the tests themselves | ||
const unstubbedSetTimeout = setTimeout; | ||
const delay = (delayMs) => | ||
new Promise((resolve) => unstubbedSetTimeout(resolve, delayMs)); | ||
class TestFile extends Blob { | ||
@@ -19,0 +13,0 @@ constructor(blobParts, name, type) { |
@@ -30,2 +30,8 @@ const IS_BROWSER = typeof window !== 'undefined' && window !== null; | ||
// Grab setTimeout before we replace it with a fake later, so | ||
// we can still do real waiting in the tests themselves | ||
const unstubbedSetTimeout = setTimeout; | ||
const delay = (delayMs) => | ||
new Promise((resolve) => unstubbedSetTimeout(resolve, delayMs)); | ||
export default () => ({ | ||
@@ -36,2 +42,3 @@ IS_BROWSER, | ||
getCustomRequest, | ||
delay, | ||
}); |
import { PassThrough } from 'stream'; | ||
import { expect } from 'chai'; | ||
import setup from './setup'; | ||
import * as Bluebird from 'bluebird'; | ||
import * as rindle from 'rindle'; | ||
import * as zlib from 'browserify-zlib'; | ||
import * as mockhttp from 'mockttp'; | ||
import * as utils from '../build/utils'; | ||
const mockServer = mockhttp.getLocal(); | ||
const { auth, request } = setup(); | ||
const gzip = Bluebird.promisify(zlib.gzip); | ||
const { auth, request, delay } = setup(); | ||
const gzip = (contents) => | ||
new Promise((resolve, reject) => | ||
zlib.gzip(contents, (err, res) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(res); | ||
} | ||
}), | ||
); | ||
@@ -56,3 +64,3 @@ describe('Request (stream):', function () { | ||
}) | ||
.then(rindle.extract) | ||
.then(utils.getStreamContents) | ||
.then((data) => expect(data).to.equal('Lorem ipsum dolor sit amet'))); | ||
@@ -67,3 +75,3 @@ | ||
}) | ||
.then((stream) => Bluebird.delay(200).return(stream)) | ||
.then((stream) => delay(200).then(() => stream)) | ||
.then(function (stream) { | ||
@@ -73,4 +81,4 @@ const pass = new PassThrough(); | ||
return rindle | ||
.extract(pass) | ||
return utils | ||
.getStreamContents(pass) | ||
.then((data) => | ||
@@ -98,3 +106,3 @@ expect(data).to.equal('Lorem ipsum dolor sit amet'), | ||
}) | ||
.then(rindle.extract) | ||
.then(utils.getStreamContents) | ||
.then((data) => expect(data).to.equal('GET')))); | ||
@@ -121,3 +129,3 @@ }); | ||
}) | ||
.then((stream) => rindle.extract(stream)) | ||
.then((stream) => utils.getStreamContents(stream)) | ||
.then(function (data) { | ||
@@ -155,3 +163,3 @@ expect(data).to.equal('Lorem ipsum dolor sit amet'); | ||
}) | ||
.then((stream) => rindle.extract(stream)) | ||
.then((stream) => utils.getStreamContents(stream)) | ||
.then(function (data) { | ||
@@ -182,3 +190,3 @@ expect(data).to.equal('Lorem ipsum dolor sit amet'); | ||
}) | ||
.then((stream) => rindle.extract(stream)) | ||
.then((stream) => utils.getStreamContents(stream)) | ||
.then(function (data) { | ||
@@ -185,0 +193,0 @@ expect(data).to.equal('Lorem ipsum dolor sit amet'); |
import { expect } from 'chai'; | ||
import setup from './setup'; | ||
import * as rindle from 'rindle'; | ||
import * as sinon from 'sinon'; | ||
@@ -310,3 +309,3 @@ import * as errors from 'balena-errors'; | ||
); | ||
return rindle.extract(stream); | ||
return utils.getStreamContents(stream); | ||
})); | ||
@@ -328,3 +327,3 @@ }); | ||
expect(headers.Authorization).to.not.exist; | ||
return rindle.extract(stream); | ||
return utils.getStreamContents(stream); | ||
})); | ||
@@ -331,0 +330,0 @@ }); |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
231829
4484
1