Skip to content

Commit 4da5d4a

Browse files
author
Michael Ng
authored
Merge branch 'master' into james/custom_condition_evaluators_OG
2 parents 0eeb31d + bd49de0 commit 4da5d4a

18 files changed

+102
-45
lines changed

packages/datafile-manager/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
Changes that have landed but are not yet released.
99

10+
## [0.4.0] - June 12, 2019
11+
12+
### Changed
13+
- Changed name of top-level exports in index.node.ts and index.browser.ts from `DatafileManager` to `HttpPollingDatafileManager`, to avoid name conflict with `DatafileManager` interface
14+
1015
## [0.3.0] - May 13, 2019
1116

1217
### New Features

packages/datafile-manager/__test__/httpPollingDatafileManager.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import HTTPPollingDatafileManager from '../src/httpPollingDatafileManager'
17+
import HttpPollingDatafileManager from '../src/httpPollingDatafileManager'
1818
import { Headers, AbortableRequest, Response } from '../src/http'
1919
import { DatafileManagerConfig } from '../src/datafileManager';
2020
import { advanceTimersByTime, getTimerCount } from './testUtils'
@@ -34,7 +34,7 @@ import BackoffController from '../src/backoffController'
3434

3535
// Test implementation:
3636
// - Does not make any real requests: just resolves with queued responses (tests push onto queuedResponses)
37-
class TestDatafileManager extends HTTPPollingDatafileManager {
37+
class TestDatafileManager extends HttpPollingDatafileManager {
3838
queuedResponses: (Response | Error)[] = []
3939

4040
responsePromises: Promise<Response>[] = []

packages/datafile-manager/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optimizely/js-sdk-datafile-manager",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Optimizely Full Stack Datafile Manager",
55
"license": "Apache-2.0",
66
"engines": {

packages/datafile-manager/src/httpPollingDatafileManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function isSuccessStatusCode(statusCode: number): boolean {
3434
return statusCode >= 200 && statusCode < 400
3535
}
3636

37-
export default abstract class HTTPPollingDatafileManager implements DatafileManager {
37+
export default abstract class HttpPollingDatafileManager implements DatafileManager {
3838
// Make an HTTP get request to the given URL with the given headers
3939
// Return an AbortableRequest, which has a promise for a Response.
4040
// If we can't get a response, the promise is rejected.
@@ -208,7 +208,7 @@ export default abstract class HTTPPollingDatafileManager implements DatafileMana
208208
}
209209
}
210210

211-
private onRequestComplete(this: HTTPPollingDatafileManager): void {
211+
private onRequestComplete(this: HttpPollingDatafileManager): void {
212212
if (!this.isStarted) {
213213
return
214214
}

packages/datafile-manager/src/index.browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
*/
1616

1717
export * from './datafileManager'
18-
export { default as DatafileManager } from './browserDatafileManager'
18+
export { default as HttpPollingDatafileManager } from './browserDatafileManager'
1919
export { default as StaticDatafileManager } from './staticDatafileManager';

packages/datafile-manager/src/index.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
*/
1616

1717
export * from './datafileManager'
18-
export { default as DatafileManager } from './nodeDatafileManager'
18+
export { default as HttpPollingDatafileManager } from './nodeDatafileManager'
1919
export { default as StaticDatafileManager } from './staticDatafileManager';

packages/event-processor/CHANGELOG.MD

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
Changes that have landed but are not yet released.
99

10+
## [0.2.1] - June 6, 2019
11+
12+
- Wrap the `callback` in `try/catch` when implementing a custom `eventDispatcher`. This ensures invoking the `callback` will always cleanup any pending retry tasks.
13+
1014
## [0.2.0] - March 27, 2019
1115

1216
- Add `PendingEventsDispatcher` to wrap another EventDispatcher with retry support for

packages/event-processor/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/event-processor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optimizely/js-sdk-event-processor",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Optimizely Full Stack Event Processor",
55
"author": "jordangarcia <[email protected]>",
66
"homepage": "https://github.com/optimizely/javascript-sdk/tree/master/packages/event-processor",

packages/optimizely-sdk/lib/core/project_config/project_config_manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ ProjectConfigManager.prototype.__initialize = function(config) {
125125
if (initialDatafile && this.__configObj) {
126126
datafileManagerConfig.datafile = initialDatafile;
127127
}
128-
this.datafileManager = new datafileManager.DatafileManager(datafileManagerConfig);
128+
this.datafileManager = new datafileManager.HttpPollingDatafileManager(datafileManagerConfig);
129129
this.datafileManager.start();
130130
this.__readyPromise = this.datafileManager.onReady().then(
131131
this.__onDatafileManagerReadyFulfill.bind(this),

packages/optimizely-sdk/lib/core/project_config/project_config_manager.tests.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var LOG_MESSAGES = enums.LOG_MESSAGES;
3131
describe('lib/core/project_config/project_config_manager', function() {
3232
var globalStubErrorHandler;
3333
beforeEach(function() {
34-
sinon.stub(datafileManager, 'DatafileManager').returns({
34+
sinon.stub(datafileManager, 'HttpPollingDatafileManager').returns({
3535
start: sinon.stub(),
3636
stop: sinon.stub(),
3737
get: sinon.stub().returns(null),
@@ -50,7 +50,7 @@ describe('lib/core/project_config/project_config_manager', function() {
5050
});
5151

5252
afterEach(function() {
53-
datafileManager.DatafileManager.restore();
53+
datafileManager.HttpPollingDatafileManager.restore();
5454
logging.resetErrorHandler();
5555
logging.resetLogger();
5656
});
@@ -187,8 +187,8 @@ describe('lib/core/project_config/project_config_manager', function() {
187187
updateInterval: 10000,
188188
},
189189
});
190-
sinon.assert.calledOnce(datafileManager.DatafileManager);
191-
sinon.assert.calledWithExactly(datafileManager.DatafileManager, sinon.match({
190+
sinon.assert.calledOnce(datafileManager.HttpPollingDatafileManager);
191+
sinon.assert.calledWithExactly(datafileManager.HttpPollingDatafileManager, sinon.match({
192192
datafile: testData.getTestProjectConfig(),
193193
sdkKey: '12345',
194194
autoUpdate: true,
@@ -199,7 +199,7 @@ describe('lib/core/project_config/project_config_manager', function() {
199199
describe('when constructed with sdkKey and without datafile', function() {
200200
it('updates itself when the datafile manager is ready, fulfills its onReady promise with a successful result, and then emits updates', function() {
201201
var configWithFeatures = testData.getTestProjectConfigWithFeatures();
202-
datafileManager.DatafileManager.returns({
202+
datafileManager.HttpPollingDatafileManager.returns({
203203
start: sinon.stub(),
204204
stop: sinon.stub(),
205205
get: sinon.stub().returns(configWithFeatures),
@@ -231,7 +231,7 @@ describe('lib/core/project_config/project_config_manager', function() {
231231
variations: [{ key: 'variation', id: '99977477477747747' }],
232232
});
233233
nextDatafile.revision = '36';
234-
var fakeDatafileManager = datafileManager.DatafileManager.getCall(0).returnValue;
234+
var fakeDatafileManager = datafileManager.HttpPollingDatafileManager.getCall(0).returnValue;
235235
fakeDatafileManager.get.returns(nextDatafile);
236236
var updateListener = fakeDatafileManager.on.getCall(0).args[1];
237237
updateListener({ datafile: nextDatafile });
@@ -243,7 +243,7 @@ describe('lib/core/project_config/project_config_manager', function() {
243243
});
244244

245245
it('calls onUpdate listeners after becoming ready, and after the datafile manager emits updates', function() {
246-
datafileManager.DatafileManager.returns({
246+
datafileManager.HttpPollingDatafileManager.returns({
247247
start: sinon.stub(),
248248
stop: sinon.stub(),
249249
get: sinon.stub().returns(testData.getTestProjectConfigWithFeatures()),
@@ -258,7 +258,7 @@ describe('lib/core/project_config/project_config_manager', function() {
258258
return manager.onReady().then(function() {
259259
sinon.assert.calledOnce(onUpdateSpy);
260260

261-
var fakeDatafileManager = datafileManager.DatafileManager.getCall(0).returnValue;
261+
var fakeDatafileManager = datafileManager.HttpPollingDatafileManager.getCall(0).returnValue;
262262
var updateListener = fakeDatafileManager.on.getCall(0).args[1];
263263
var newDatafile = testData.getTestProjectConfigWithFeatures();
264264
newDatafile.revision = '36';
@@ -270,7 +270,7 @@ describe('lib/core/project_config/project_config_manager', function() {
270270
});
271271

272272
it('can remove onUpdate listeners using the function returned from onUpdate', function() {
273-
datafileManager.DatafileManager.returns({
273+
datafileManager.HttpPollingDatafileManager.returns({
274274
start: sinon.stub(),
275275
stop: sinon.stub(),
276276
get: sinon.stub().returns(testData.getTestProjectConfigWithFeatures()),
@@ -284,7 +284,7 @@ describe('lib/core/project_config/project_config_manager', function() {
284284
var onUpdateSpy = sinon.spy();
285285
var unsubscribe = manager.onUpdate(onUpdateSpy);
286286

287-
var fakeDatafileManager = datafileManager.DatafileManager.getCall(0).returnValue;
287+
var fakeDatafileManager = datafileManager.HttpPollingDatafileManager.getCall(0).returnValue;
288288
var updateListener = fakeDatafileManager.on.getCall(0).args[1];
289289
var newDatafile = testData.getTestProjectConfigWithFeatures();
290290
newDatafile.revision = '36';
@@ -308,7 +308,7 @@ describe('lib/core/project_config/project_config_manager', function() {
308308
it('fulfills its ready promise with an unsuccessful result when the datafile manager emits an invalid datafile', function() {
309309
var invalidDatafile = testData.getTestProjectConfig();
310310
delete invalidDatafile['projectId'];
311-
datafileManager.DatafileManager.returns({
311+
datafileManager.HttpPollingDatafileManager.returns({
312312
start: sinon.stub(),
313313
stop: sinon.stub(),
314314
get: sinon.stub().returns(invalidDatafile),
@@ -327,7 +327,7 @@ describe('lib/core/project_config/project_config_manager', function() {
327327
});
328328

329329
it('fullfils its ready promise with an unsuccessful result when the datafile manager onReady promise rejects', function() {
330-
datafileManager.DatafileManager.returns({
330+
datafileManager.HttpPollingDatafileManager.returns({
331331
start: sinon.stub(),
332332
stop: sinon.stub(),
333333
get: sinon.stub().returns(null),
@@ -350,13 +350,13 @@ describe('lib/core/project_config/project_config_manager', function() {
350350
sdkKey: '12345',
351351
});
352352
manager.stop();
353-
sinon.assert.calledOnce(datafileManager.DatafileManager.getCall(0).returnValue.stop);
353+
sinon.assert.calledOnce(datafileManager.HttpPollingDatafileManager.getCall(0).returnValue.stop);
354354
});
355355
});
356356

357357
describe('when constructed with sdkKey and with a valid datafile object', function() {
358358
it('fulfills its onReady promise with a successful result, and does not call onUpdate listeners after becoming ready', function() {
359-
datafileManager.DatafileManager.returns({
359+
datafileManager.HttpPollingDatafileManager.returns({
360360
start: sinon.stub(),
361361
stop: sinon.stub(),
362362
get: sinon.stub().returns(testData.getTestProjectConfigWithFeatures()),
@@ -383,7 +383,7 @@ describe('lib/core/project_config/project_config_manager', function() {
383383

384384
describe('when constructed with sdkKey and with a valid datafile string', function() {
385385
it('fulfills its onReady promise with a successful result, and does not call onUpdate listeners after becoming ready', function() {
386-
datafileManager.DatafileManager.returns({
386+
datafileManager.HttpPollingDatafileManager.returns({
387387
start: sinon.stub(),
388388
stop: sinon.stub(),
389389
get: sinon.stub().returns(testData.getTestProjectConfigWithFeatures()),

packages/optimizely-sdk/lib/index.browser.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,26 @@ module.exports = {
8585
config.skipJSONValidation = true;
8686
}
8787

88-
var wrappedEventDispatcher = new eventProcessor.LocalStoragePendingEventsDispatcher({
89-
eventDispatcher: config.eventDispatcher || defaultEventDispatcher,
90-
});
91-
if (!hasRetriedEvents) {
92-
wrappedEventDispatcher.sendPendingEvents();
93-
hasRetriedEvents = true;
88+
var eventDispatcher;
89+
// prettier-ignore
90+
if (config.eventDispatcher == null) { // eslint-disable-line eqeqeq
91+
// only wrap the event dispatcher with pending events retry if the user didnt override
92+
eventDispatcher = new eventProcessor.LocalStoragePendingEventsDispatcher({
93+
eventDispatcher: defaultEventDispatcher,
94+
});
95+
96+
if (!hasRetriedEvents) {
97+
eventDispatcher.sendPendingEvents();
98+
hasRetriedEvents = true;
99+
}
100+
} else {
101+
eventDispatcher = config.eventDispatcher;
94102
}
95103

96104
config = fns.assignIn({
97105
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
98106
}, config, {
99-
eventDispatcher: wrappedEventDispatcher,
107+
eventDispatcher: eventDispatcher,
100108
// always get the OptimizelyLogger facade from logging
101109
logger: logger,
102110
errorHandler: logging.getErrorHandler(),

packages/optimizely-sdk/lib/index.browser.tests.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('javascript-sdk', function() {
6262
requests.push(req);
6363
};
6464

65-
sinon.spy(LocalStoragePendingEventsDispatcher.prototype, 'sendPendingEvents');
65+
sinon.stub(LocalStoragePendingEventsDispatcher.prototype, 'sendPendingEvents');
6666
});
6767

6868
afterEach(function() {
@@ -73,11 +73,39 @@ describe('javascript-sdk', function() {
7373
xhr.restore();
7474
});
7575

76+
describe('when an eventDispatcher is not passed in', function() {
77+
it('should wrap the default eventDispatcher and invoke sendPendingEvents', function() {
78+
var optlyInstance = optimizelyFactory.createInstance({
79+
datafile: {},
80+
errorHandler: fakeErrorHandler,
81+
logger: silentLogger,
82+
});
83+
// Invalid datafile causes onReady Promise rejection - catch this error
84+
optlyInstance.onReady().catch(function() {});
85+
86+
sinon.assert.calledOnce(LocalStoragePendingEventsDispatcher.prototype.sendPendingEvents);
87+
});
88+
});
89+
90+
describe('when an eventDispatcher is passed in', function() {
91+
it('should NOT wrap the default eventDispatcher and invoke sendPendingEvents', function() {
92+
var optlyInstance = optimizelyFactory.createInstance({
93+
datafile: {},
94+
errorHandler: fakeErrorHandler,
95+
eventDispatcher: fakeEventDispatcher,
96+
logger: silentLogger,
97+
});
98+
// Invalid datafile causes onReady Promise rejection - catch this error
99+
optlyInstance.onReady().catch(function() {});
100+
101+
sinon.assert.notCalled(LocalStoragePendingEventsDispatcher.prototype.sendPendingEvents);
102+
});
103+
});
104+
76105
it('should invoke resendPendingEvents at most once', function() {
77106
var optlyInstance = optimizelyFactory.createInstance({
78107
datafile: {},
79108
errorHandler: fakeErrorHandler,
80-
eventDispatcher: fakeEventDispatcher,
81109
logger: silentLogger,
82110
});
83111
// Invalid datafile causes onReady Promise rejection - catch this error
@@ -88,7 +116,6 @@ describe('javascript-sdk', function() {
88116
optlyInstance = optimizelyFactory.createInstance({
89117
datafile: {},
90118
errorHandler: fakeErrorHandler,
91-
eventDispatcher: fakeEventDispatcher,
92119
logger: silentLogger,
93120
});
94121
optlyInstance.onReady().catch(function() {});

packages/optimizely-sdk/package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/optimizely-sdk/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
},
3333
"homepage": "https://github.com/optimizely/javascript-sdk/tree/master/packages/optimizely-sdk",
3434
"dependencies": {
35-
"@optimizely/js-sdk-datafile-manager": "^0.3.0",
36-
"@optimizely/js-sdk-event-processor": "^0.2.0",
35+
"@optimizely/js-sdk-datafile-manager": "^0.4.0",
36+
"@optimizely/js-sdk-event-processor": "^0.2.1",
3737
"@optimizely/js-sdk-logging": "^0.1.0",
3838
"@optimizely/js-sdk-utils": "^0.1.0",
3939
"json-schema": "^0.2.3",

packages/utils/CHANGELOG.MD

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
Changes that have landed but are not yet released.
99

10+
### New Features
11+
- Added `objectEntries`
12+
1013
## [0.1.0] - March 1, 2019
1114

12-
Initial release
15+
Initial release

packages/utils/__tests__/utils.spec.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="jest" />
2-
import { isValidEnum, groupBy, objectValues, find, keyBy, sprintf } from '../src'
2+
import { isValidEnum, groupBy, objectEntries, objectValues, find, keyBy, sprintf } from '../src'
33

44
describe('utils', () => {
55
describe('isValidEnum', () => {
@@ -37,6 +37,12 @@ describe('utils', () => {
3737
})
3838
})
3939

40+
describe('objectEntries', () => {
41+
it('should return object entries', () => {
42+
expect(objectEntries({ foo: 'bar', bar: 123 })).toEqual([['foo', 'bar'], ['bar', 123]])
43+
})
44+
})
45+
4046
describe('objectValues', () => {
4147
it('should return object values', () => {
4248
expect(objectValues({ foo: 'bar', bar: 123 })).toEqual(['bar', 123])

0 commit comments

Comments
 (0)