balena-request
Advanced tools
Comparing version 11.5.1-move-response-body-error-to-response-body-message-if-there-is-one-d7ee386eecbb1438e488c939ddb9d2dbf4ff4caf to 11.5.1
@@ -118,8 +118,2 @@ "use strict"; | ||
} | ||
if (response.body != null && typeof response.body === 'object') { | ||
const bodyMessageProp = ['message', 'error'].find((prop) => typeof response.body[prop] === 'string'); | ||
if (bodyMessageProp != null) { | ||
return response.body[bodyMessageProp]; | ||
} | ||
} | ||
return response.body; | ||
@@ -126,0 +120,0 @@ } |
@@ -8,5 +8,5 @@ # Change Log | ||
# v11.5.1 | ||
## (2022-03-31) | ||
## (2022-04-04) | ||
* Use response error as response message if there is one [Matthew Yarmolinsky] | ||
* Drop mochainon & bump karma [Thodoris Greasidis] | ||
@@ -13,0 +13,0 @@ # v11.5.0 |
@@ -121,11 +121,2 @@ /* | ||
if (response.body != null && typeof response.body === 'object') { | ||
const bodyMessageProp = ['message', 'error'].find( | ||
(prop) => typeof response.body[prop] === 'string', | ||
); | ||
if (bodyMessageProp != null) { | ||
return response.body[bodyMessageProp]; | ||
} | ||
} | ||
return response.body; | ||
@@ -132,0 +123,0 @@ } |
{ | ||
"name": "balena-request", | ||
"version": "11.5.1-move-response-body-error-to-response-body-message-if-there-is-one-d7ee386eecbb1438e488c939ddb9d2dbf4ff4caf", | ||
"version": "11.5.1", | ||
"description": "Balena HTTP client", | ||
@@ -37,14 +37,21 @@ "main": "build/request.js", | ||
"@balena/lint": "^5.1.0", | ||
"@types/chai": "^4.3.0", | ||
"@types/chai-as-promised": "^7.1.5", | ||
"@types/mocha": "^7.0.2", | ||
"@types/progress-stream": "^2.0.0", | ||
"@types/qs": "^6.9.3", | ||
"@types/sinon": "^10.0.11", | ||
"balena-auth": "^4.1.0", | ||
"balena-config-karma": "^3.0.0", | ||
"bluebird": "^3.7.2", | ||
"chai": "^4.3.4", | ||
"chai-as-promised": "^7.1.1", | ||
"jsdoc-to-markdown": "^6.0.1", | ||
"karma": "^3.1.4", | ||
"mocha": "^3.5.3", | ||
"mochainon": "^2.0.0", | ||
"karma": "^5.0.9", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"mocha": "^7.2.0", | ||
"mockttp": "^0.8.1", | ||
"require-npm4-to-publish": "^1.0.0", | ||
"rindle": "^1.3.6", | ||
"sinon": "^13.0.1", | ||
"temp": "^0.8.4", | ||
@@ -68,4 +75,4 @@ "timekeeper": "^1.0.0", | ||
"versionist": { | ||
"publishedAt": "2022-03-31T15:55:40.152Z" | ||
"publishedAt": "2022-04-04T13:06:30.892Z" | ||
} | ||
} |
@@ -1,3 +0,4 @@ | ||
const m = require('mochainon'); | ||
const { expect } = require('chai'); | ||
const rindle = require('rindle'); | ||
const sinon = require('sinon'); | ||
const johnDoeFixture = require('./tokens.json').johndoe; | ||
@@ -10,4 +11,2 @@ const utils = require('../build/utils'); | ||
const { expect } = m.chai; | ||
describe('Request (api key):', function () { | ||
@@ -22,3 +21,3 @@ this.timeout(10000); | ||
beforeEach(function () { | ||
this.utilsShouldUpdateToken = m.sinon.stub(utils, 'shouldRefreshKey'); | ||
this.utilsShouldUpdateToken = sinon.stub(utils, 'shouldRefreshKey'); | ||
return this.utilsShouldUpdateToken.returns(Promise.resolve(false)); | ||
@@ -25,0 +24,0 @@ }); |
@@ -0,5 +1,5 @@ | ||
const { expect } = require('chai'); | ||
const rindle = require('rindle'); | ||
const sinon = require('sinon'); | ||
const Bluebird = require('bluebird'); | ||
const m = require('mochainon'); | ||
const mockServer = require('mockttp').getLocal(); | ||
@@ -11,4 +11,2 @@ | ||
const { expect } = m.chai; | ||
describe('An interceptor', function () { | ||
@@ -120,5 +118,5 @@ this.timeout(10000); | ||
}, | ||
requestError: m.sinon.mock(), | ||
requestError: sinon.mock(), | ||
}; | ||
request.interceptors[1] = { requestError: m.sinon.mock() }; | ||
request.interceptors[1] = { requestError: sinon.mock() }; | ||
@@ -142,7 +140,7 @@ return request | ||
request.interceptors[0] = { | ||
request: m.sinon.mock().throws(new Error('blocked')), | ||
requestError: m.sinon.mock(), | ||
request: sinon.mock().throws(new Error('blocked')), | ||
requestError: sinon.mock(), | ||
}; | ||
request.interceptors[1] = { | ||
requestError: m.sinon.mock().throws(new Error('error overridden')), | ||
requestError: sinon.mock().throws(new Error('error overridden')), | ||
}; | ||
@@ -167,3 +165,3 @@ | ||
beforeEach(function () { | ||
return (this.utilsShouldUpdateToken = m.sinon | ||
return (this.utilsShouldUpdateToken = sinon | ||
.stub(utils, 'shouldRefreshKey') | ||
@@ -180,3 +178,3 @@ .returns(true)); | ||
request.interceptors[0] = { | ||
requestError: m.sinon | ||
requestError: sinon | ||
.mock() | ||
@@ -196,3 +194,3 @@ .throws(new Error('intercepted auth failure')), | ||
request.interceptors[0] = { | ||
requestError: m.sinon | ||
requestError: sinon | ||
.mock() | ||
@@ -214,3 +212,3 @@ .throws(new Error('intercepted auth failure')), | ||
request.interceptors[0] = { | ||
requestError: m.sinon | ||
requestError: sinon | ||
.mock() | ||
@@ -229,3 +227,3 @@ .throws(new Error('intercepted auth failure')), | ||
request.interceptors[0] = { | ||
requestError: m.sinon | ||
requestError: sinon | ||
.mock() | ||
@@ -319,3 +317,3 @@ .throws(new Error('intercepted auth failure')), | ||
it('should not call responseError if there are no errors', function () { | ||
request.interceptors[0] = { responseError: m.sinon.mock() }; | ||
request.interceptors[0] = { responseError: sinon.mock() }; | ||
@@ -341,3 +339,3 @@ return request | ||
request.interceptors[0] = { | ||
responseError: m.sinon.mock().throws(new Error('caught error')), | ||
responseError: sinon.mock().throws(new Error('caught error')), | ||
}; | ||
@@ -358,5 +356,3 @@ | ||
request.interceptors[0] = { | ||
responseError: m.sinon | ||
.mock() | ||
.throws(new Error('caught auth error')), | ||
responseError: sinon.mock().throws(new Error('caught auth error')), | ||
}; | ||
@@ -447,3 +443,3 @@ | ||
request.interceptors[0] = { | ||
responseError: m.sinon.mock().throws(new Error('caught error')), | ||
responseError: sinon.mock().throws(new Error('caught error')), | ||
}; | ||
@@ -450,0 +446,0 @@ |
const Bluebird = require('bluebird'); | ||
const m = require('mochainon'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
@@ -8,4 +9,2 @@ const mockServer = require('mockttp').getLocal(); | ||
const { expect } = m.chai; | ||
// Grab setTimeout before we replace it with a fake later, so | ||
@@ -276,3 +275,3 @@ // we can still do real waiting in the tests themselves | ||
beforeEach(function () { | ||
this.clock = m.sinon.useFakeTimers(); | ||
this.clock = sinon.useFakeTimers(); | ||
return mockServer.get('/infinite-wait').thenTimeout(); | ||
@@ -279,0 +278,0 @@ }); |
const Bluebird = require('bluebird'); | ||
const m = require('mochainon'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const errors = require('balena-errors'); | ||
@@ -9,4 +10,2 @@ | ||
const { expect } = m.chai; | ||
const RESPONSE_BODY = { from: 'foobar' }; | ||
@@ -13,0 +12,0 @@ |
@@ -20,2 +20,5 @@ const IS_BROWSER = typeof window !== 'undefined' && window !== null; | ||
const { getRequest } = require('../build/request'); | ||
const chai = require('chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
chai.use(chaiAsPromised); | ||
@@ -22,0 +25,0 @@ const getCustomRequest = function (opts) { |
const Bluebird = require('bluebird'); | ||
const m = require('mochainon'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const zlib = require('zlib-browserify'); | ||
@@ -13,4 +14,2 @@ const { PassThrough } = require('stream'); | ||
const { expect } = m.chai; | ||
describe('Request (stream):', function () { | ||
@@ -17,0 +16,0 @@ beforeEach(() => Promise.all([auth.removeKey(), mockServer.start()])); |
@@ -1,2 +0,3 @@ | ||
const m = require('mochainon'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const errors = require('balena-errors'); | ||
@@ -14,4 +15,2 @@ const rindle = require('rindle'); | ||
const { expect } = m.chai; | ||
describe('Request (token):', function () { | ||
@@ -30,3 +29,3 @@ this.timeout(10000); | ||
beforeEach(function () { | ||
this.utilsShouldUpdateToken = m.sinon.stub(utils, 'shouldRefreshKey'); | ||
this.utilsShouldUpdateToken = sinon.stub(utils, 'shouldRefreshKey'); | ||
return this.utilsShouldUpdateToken.returns(Promise.resolve(false)); | ||
@@ -86,6 +85,6 @@ }); | ||
beforeEach(function () { | ||
this.utilsShouldUpdateToken = m.sinon.stub(utils, 'shouldRefreshKey'); | ||
this.utilsShouldUpdateToken = sinon.stub(utils, 'shouldRefreshKey'); | ||
this.utilsShouldUpdateToken.returns(Promise.resolve(true)); | ||
this.authIsExpired = m.sinon.stub(auth, 'isExpired'); | ||
this.authIsExpired = sinon.stub(auth, 'isExpired'); | ||
this.authIsExpired.returns(Promise.resolve(false)); | ||
@@ -248,3 +247,3 @@ | ||
beforeEach(function () { | ||
this.utilsShouldUpdateToken = m.sinon.stub(utils, 'shouldRefreshKey'); | ||
this.utilsShouldUpdateToken = sinon.stub(utils, 'shouldRefreshKey'); | ||
return this.utilsShouldUpdateToken.returns(Promise.resolve(false)); | ||
@@ -251,0 +250,0 @@ }); |
const ReadableStream = require('stream').Readable; | ||
const { Headers } = require('fetch-ponyfill')({ Promise }); | ||
const m = require('mochainon'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const johnDoeFixture = require('./tokens.json').johndoe; | ||
@@ -11,4 +12,2 @@ const utils = require('../build/utils'); | ||
const { expect } = m.chai; | ||
describe('Utils:', function () { | ||
@@ -18,5 +17,5 @@ describe('.shouldRefreshKey()', function () { | ||
beforeEach(function () { | ||
this.tokenHasKeyStub = m.sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub = sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub.returns(Promise.resolve(true)); | ||
this.tokenGetTypeStub = m.sinon.stub(auth, 'getType'); | ||
this.tokenGetTypeStub = sinon.stub(auth, 'getType'); | ||
return this.tokenGetTypeStub.returns(Promise.resolve('APIKey')); | ||
@@ -36,9 +35,9 @@ }); | ||
beforeEach(function () { | ||
this.tokenGetAgeStub = m.sinon.stub(auth, 'getAge'); | ||
this.tokenGetAgeStub = sinon.stub(auth, 'getAge'); | ||
this.tokenGetAgeStub.returns( | ||
Promise.resolve(utils.TOKEN_REFRESH_INTERVAL + 1), | ||
); | ||
this.tokenHasKeyStub = m.sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub = sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub.returns(Promise.resolve(true)); | ||
this.tokenGetTypeStub = m.sinon.stub(auth, 'getType'); | ||
this.tokenGetTypeStub = sinon.stub(auth, 'getType'); | ||
return this.tokenGetTypeStub.returns(Promise.resolve(TokenType.JWT)); | ||
@@ -59,9 +58,9 @@ }); | ||
beforeEach(function () { | ||
this.tokenGetAgeStub = m.sinon.stub(auth, 'getAge'); | ||
this.tokenGetAgeStub = sinon.stub(auth, 'getAge'); | ||
this.tokenGetAgeStub.returns( | ||
Promise.resolve(utils.TOKEN_REFRESH_INTERVAL - 1), | ||
); | ||
this.tokenHasKeyStub = m.sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub = sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub.returns(Promise.resolve(true)); | ||
this.tokenGetTypeStub = m.sinon.stub(auth, 'getType'); | ||
this.tokenGetTypeStub = sinon.stub(auth, 'getType'); | ||
return this.tokenGetTypeStub.returns(Promise.resolve(TokenType.JWT)); | ||
@@ -82,9 +81,9 @@ }); | ||
beforeEach(function () { | ||
this.tokenGetAgeStub = m.sinon.stub(auth, 'getAge'); | ||
this.tokenGetAgeStub = sinon.stub(auth, 'getAge'); | ||
this.tokenGetAgeStub.returns( | ||
Promise.resolve(utils.TOKEN_REFRESH_INTERVAL), | ||
); | ||
this.tokenHasKeyStub = m.sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub = sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub.returns(Promise.resolve(true)); | ||
this.tokenGetTypeStub = m.sinon.stub(auth, 'getType'); | ||
this.tokenGetTypeStub = sinon.stub(auth, 'getType'); | ||
return this.tokenGetTypeStub.returns(Promise.resolve(TokenType.JWT)); | ||
@@ -105,3 +104,3 @@ }); | ||
beforeEach(function () { | ||
this.tokenHasKeyStub = m.sinon.stub(auth, 'hasKey'); | ||
this.tokenHasKeyStub = sinon.stub(auth, 'hasKey'); | ||
return this.tokenHasKeyStub.returns(Promise.resolve(false)); | ||
@@ -108,0 +107,0 @@ }); |
@@ -14,6 +14,2 @@ { | ||
"moduleResolution": "node", | ||
"typeRoots": [ | ||
"node_modules/@types", | ||
"node_modules/@resin.io" | ||
], | ||
"allowJs": true, | ||
@@ -20,0 +16,0 @@ "checkJs": true, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
199886
24
3968