Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "1.2.1-rc.5",
"version": "1.2.1-rc.7",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
3 changes: 2 additions & 1 deletion src/sync/streaming/SSEClient/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IEventSourceConstructor } from '../../../services/types';
import { ISettings } from '../../../types';
import { isString } from '../../../utils/lang';
import { IAuthTokenPushEnabled } from '../AuthClient/types';
import { ISSEClient, ISseEventHandler } from './types';

Expand All @@ -15,7 +16,7 @@ const CONTROL_CHANNEL_REGEX = /^control_/;
*/
function buildSSEHeaders(settings: ISettings) {
const headers: Record<string, string> = {
SplitSDKClientKey: settings.core.authorizationKey.slice(-4),
SplitSDKClientKey: isString(settings.core.authorizationKey) ? settings.core.authorizationKey.slice(-4) : '',
SplitSDKVersion: settings.version,
};

Expand Down
61 changes: 61 additions & 0 deletions src/sync/submitters/__tests__/eventsSyncTask.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { eventsSyncTaskFactory } from '../eventsSyncTask';
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';



describe('Events submitter (eventsSyncTask)', () => {

let __onFullQueueCb: () => void;
const postEventsBulkMock = jest.fn();
const eventsCacheMock = {
isEmpty: jest.fn(() => true),
setOnFullQueueCb: jest.fn(function (onFullQueueCb) { __onFullQueueCb = onFullQueueCb; })
};

beforeEach(() => {
eventsCacheMock.isEmpty.mockClear();
});

test('with eventsFirstPushWindow', async () => {
const eventsFirstPushWindow = 20; // @ts-ignore
const eventsSubmitter = eventsSyncTaskFactory(loggerMock, postEventsBulkMock, eventsCacheMock, 30000, eventsFirstPushWindow);

eventsSubmitter.start();
expect(eventsSubmitter.isRunning()).toEqual(true); // Submitter should be flagged as running
expect(eventsSubmitter.isExecuting()).toEqual(false); // but not executed immediatelly if there is a push window
expect(eventsCacheMock.isEmpty).not.toBeCalled();

// If queue is full, submitter should be executed
__onFullQueueCb();
expect(eventsSubmitter.isExecuting()).toEqual(true);
expect(eventsCacheMock.isEmpty).toBeCalledTimes(1);

// Await first push window
await new Promise(res => setTimeout(res, eventsFirstPushWindow + 10));
expect(eventsCacheMock.isEmpty).toBeCalledTimes(2); // after the push window, submitter should have been executed

expect(eventsSubmitter.isRunning()).toEqual(true);
eventsSubmitter.stop();
expect(eventsSubmitter.isRunning()).toEqual(false);
});

test('without eventsFirstPushWindow', async () => {
// @ts-ignore
const eventsSubmitter = eventsSyncTaskFactory(loggerMock, postEventsBulkMock, eventsCacheMock, 30000);

eventsSubmitter.start();
expect(eventsSubmitter.isRunning()).toEqual(true); // Submitter should be flagged as running
expect(eventsSubmitter.isExecuting()).toEqual(true); // and executes immediatelly if there isn't a push window
expect(eventsCacheMock.isEmpty).toBeCalledTimes(1);

// If queue is full, submitter should be executed
__onFullQueueCb();
expect(eventsSubmitter.isExecuting()).toEqual(true);
expect(eventsCacheMock.isEmpty).toBeCalledTimes(2);

expect(eventsSubmitter.isRunning()).toEqual(true);
eventsSubmitter.stop();
expect(eventsSubmitter.isRunning()).toEqual(false);
});

});
9 changes: 8 additions & 1 deletion src/sync/submitters/eventsSyncTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ export function eventsSyncTaskFactory(
// don't retry events.
const syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);

// Set a timer for the first push of events,
// Set a timer for the first push window of events.
// Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
if (eventsFirstPushWindow > 0) {
let running = false;
let stopEventPublisherTimeout: ReturnType<typeof setTimeout>;
const originalStart = syncTask.start;
syncTask.start = () => {
running = true;
stopEventPublisherTimeout = setTimeout(originalStart, eventsFirstPushWindow);
};
const originalStop = syncTask.stop;
syncTask.stop = () => {
running = false;
clearTimeout(stopEventPublisherTimeout);
originalStop();
};
syncTask.isRunning = () => {
return running;
};
}

// register events submitter to be executed when events cache is full
Expand Down
3 changes: 2 additions & 1 deletion src/utils/settingsValidation/consent.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ConsentStatus } from '../../types';
import { CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN } from '../constants';
import { stringToUpperCase } from '../lang';

const userConsentValues = [CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN];

export function validateConsent({ userConsent, log }: { userConsent: any, log: ILogger }) {
export function validateConsent({ userConsent, log }: { userConsent?: any, log: ILogger }): ConsentStatus {
userConsent = stringToUpperCase(userConsent);

if (userConsentValues.indexOf(userConsent) > -1) return userConsent;
Expand Down