From 9c96890ecccadfba9ca81822ba9e5723645b9948 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Thu, 27 Apr 2023 19:40:22 +0400 Subject: [PATCH] fix: do not overwrite flushIntervalMillis=0 with default value (10 seconds) (#589) --- src/amplitude-client.js | 4 +++- test/amplitude-client.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/amplitude-client.js b/src/amplitude-client.js index 9527a5a1..b40f01c2 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -413,6 +413,8 @@ var _parseConfig = function _parseConfig(options, config) { // Add exception in headers const freeFormObjectKeys = new Set(['headers']); + const zeroAllowedKeys = new Set(['eventUploadPeriodMillis']); + // validates config value is defined, is the correct type, and some additional value sanity checks var parseValidateAndLoad = function parseValidateAndLoad(key) { if (!Object.prototype.hasOwnProperty.call(options, key)) { @@ -433,7 +435,7 @@ var _parseConfig = function _parseConfig(options, config) { options[key] = !!inputValue; } else if ( (expectedType === 'string' && !utils.isEmptyString(inputValue)) || - (expectedType === 'number' && inputValue > 0) || + (expectedType === 'number' && (inputValue > 0 || (inputValue === 0 && zeroAllowedKeys.has(key)))) || expectedType === 'function' ) { options[key] = inputValue; diff --git a/test/amplitude-client.js b/test/amplitude-client.js index 4d624f56..52d551fc 100644 --- a/test/amplitude-client.js +++ b/test/amplitude-client.js @@ -227,6 +227,15 @@ describe('AmplitudeClient', function () { assert.equal(amplitude.options.bogusKey, undefined); }); + it('should not overwrite eventUploadPeriodMillis=0 with default value', function () { + var config = { + eventUploadPeriodMillis: 0, + }; + + amplitude.init(apiKey, userId, config); + assert.equal(amplitude.options.eventUploadPeriodMillis, 0); + }); + it('should set the default log level', function () { const config = {};