Skip to content

Commit 9c96890

Browse files
authored
fix: do not overwrite flushIntervalMillis=0 with default value (10 seconds) (#589)
1 parent 94e9d61 commit 9c96890

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/amplitude-client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ var _parseConfig = function _parseConfig(options, config) {
413413
// Add exception in headers
414414
const freeFormObjectKeys = new Set(['headers']);
415415

416+
const zeroAllowedKeys = new Set(['eventUploadPeriodMillis']);
417+
416418
// validates config value is defined, is the correct type, and some additional value sanity checks
417419
var parseValidateAndLoad = function parseValidateAndLoad(key) {
418420
if (!Object.prototype.hasOwnProperty.call(options, key)) {
@@ -433,7 +435,7 @@ var _parseConfig = function _parseConfig(options, config) {
433435
options[key] = !!inputValue;
434436
} else if (
435437
(expectedType === 'string' && !utils.isEmptyString(inputValue)) ||
436-
(expectedType === 'number' && inputValue > 0) ||
438+
(expectedType === 'number' && (inputValue > 0 || (inputValue === 0 && zeroAllowedKeys.has(key)))) ||
437439
expectedType === 'function'
438440
) {
439441
options[key] = inputValue;

test/amplitude-client.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ describe('AmplitudeClient', function () {
227227
assert.equal(amplitude.options.bogusKey, undefined);
228228
});
229229

230+
it('should not overwrite eventUploadPeriodMillis=0 with default value', function () {
231+
var config = {
232+
eventUploadPeriodMillis: 0,
233+
};
234+
235+
amplitude.init(apiKey, userId, config);
236+
assert.equal(amplitude.options.eventUploadPeriodMillis, 0);
237+
});
238+
230239
it('should set the default log level', function () {
231240
const config = {};
232241

0 commit comments

Comments
 (0)