From 29ee2fafd83d9d3fd8654388a4c39e8aa92bcac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20R=C3=B3g?= Date: Sat, 17 Feb 2024 21:42:37 +0100 Subject: [PATCH 1/3] Fix query string not passed after replacing `request` library with `superagent` --- CHANGELOG.md | 7 +++++-- lib/chartmogul/util/retry.js | 1 + package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 104f534..a180cd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning]. [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html -## [3.2.3] - 2023-01-19 +## [3.2.4] - 2024-02-17 +- Fix query string not passed after replacing `request` library with `superagent` + +## [3.2.3] - 2024-01-19 - Actually remove the `requests` library from `package.json` -## [3.2.2] - 2023-01-18 +## [3.2.2] - 2024-01-18 - Remove the `requests` library and use `superagent` instead ## [3.2.1] - 2023-12-20 diff --git a/lib/chartmogul/util/retry.js b/lib/chartmogul/util/retry.js index 60e0490..190ac9e 100644 --- a/lib/chartmogul/util/retry.js +++ b/lib/chartmogul/util/retry.js @@ -49,6 +49,7 @@ module.exports = function retryRequest (retries, options, cb) { const request = superagent(options.method || 'get', requestUrl) .auth(options.auth.user, options.auth.pass) .set(options.headers) + .query(options.qs) .send(options.body); request.end((err, res) => { diff --git a/package-lock.json b/package-lock.json index 4f660ee..703e7c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "chartmogul-node", - "version": "3.2.2", + "version": "3.2.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "chartmogul-node", - "version": "3.2.2", + "version": "3.2.4", "license": "MIT", "dependencies": { "nyc": "^15.1.0", diff --git a/package.json b/package.json index 018c325..48dbd55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chartmogul-node", - "version": "3.2.3", + "version": "3.2.4", "description": "Official Chartmogul API Node.js Client", "main": "lib/chartmogul.js", "scripts": { From 6bb7bc8709e45dba7a8a65e3ea223e3e452f0016 Mon Sep 17 00:00:00 2001 From: alpdal Date: Wed, 28 Feb 2024 11:43:41 +0100 Subject: [PATCH 2/3] Add retriable test --- test/chartmogul/util/retry.js | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/chartmogul/util/retry.js diff --git a/test/chartmogul/util/retry.js b/test/chartmogul/util/retry.js new file mode 100644 index 0000000..508c1de --- /dev/null +++ b/test/chartmogul/util/retry.js @@ -0,0 +1,44 @@ +'use strict'; + +const ChartMogul = require('../../../lib/chartmogul'); +const expect = require('chai').expect; +const nock = require('nock'); +const config = new ChartMogul.Config('token'); +const retryRequest = require('../../../lib/chartmogul/util/retry'); + +describe('RetryTest', () => { + config.retries = 2; + const mockSuccessResponse = { success: true }; + + it('should retry on network error and then succeed', done => { + const query = { email: 'bob@acme.com' }; + + nock(config.API_BASE) + .get('/v1/metrics/all') + .query(query) + .replyWithError({ code: 'ECONNRESET' }) + .get('/v1/metrics/all') + .query(query) + .reply(200, mockSuccessResponse); + + const options = { + uri: '/v1/metrics/all', + baseUrl: config.API_BASE, + method: 'GET', + auth: { + user: config.getApiKey(), + pass: '' + }, + qs: { email: 'bob@acme.com' }, + headers: { + 'User-Agent': 'chartmogul-node/' + config.VERSION + } + }; + + retryRequest(config.retries, options, (err, res, body) => { + expect(err).to.equal(null); + expect(body).to.deep.equal(mockSuccessResponse); + done(); + }); + }); +}); From 84258f9205b1b2ed06df6dd0639c91b94fad8ddb Mon Sep 17 00:00:00 2001 From: alpdal Date: Wed, 28 Feb 2024 11:48:27 +0100 Subject: [PATCH 3/3] Update version, changelog --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a180cd0..f0f8c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning]. [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html -## [3.2.4] - 2024-02-17 +## [3.3.2] - 2024-02-28 - Fix query string not passed after replacing `request` library with `superagent` ## [3.2.3] - 2024-01-19 diff --git a/package.json b/package.json index a130258..87a7083 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chartmogul-node", - "version": "3.2.4", + "version": "3.3.2", "description": "Official Chartmogul API Node.js Client", "main": "lib/chartmogul.js", "scripts": {