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
92 changes: 39 additions & 53 deletions package-lock.json

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

13 changes: 7 additions & 6 deletions 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.0",
"version": "1.2.1-rc.3",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand All @@ -20,8 +20,8 @@
"check:lint": "eslint src --ext .js,.ts",
"check:types": "tsc --noEmit",
"build": "npm run build:cjs && npm run build:esm",
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types --importHelpers",
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs --importHelpers",
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
"test": "jest",
"test:coverage": "jest --coverage",
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
Expand All @@ -44,11 +44,12 @@
"bugs": "https://github.com/splitio/javascript-commons/issues",
"homepage": "https://github.com/splitio/javascript-commons#readme",
"dependencies": {
"tslib": "^2.1.0"
"tslib": "^2.3.1"
},
"devDependencies": {
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"@types/ip": "^1.1.0",
"@types/jest": "^27.0.0",
"@types/lodash": "^4.14.162",
"@typescript-eslint/eslint-plugin": "^4.2.0",
Expand All @@ -58,7 +59,7 @@
"eslint": "^7.32.0",
"eslint-plugin-compat": "3.7.0",
"eslint-plugin-import": "^2.25.3",
"fetch-mock": "^9.10.7",
"fetch-mock": "^9.11.0",
"ioredis": "^4.28.0",
"jest": "^27.2.3",
"jest-localstorage-mock": "^2.4.3",
Expand All @@ -68,7 +69,7 @@
"redis-server": "1.2.2",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"typescript": "^4.0.2"
"typescript": "4.4.4"
},
"sideEffects": false
}
5 changes: 3 additions & 2 deletions src/__tests__/testUtils/fetchMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sandbox } from 'fetch-mock';
// http://www.wheresrhys.co.uk/fetch-mock/#usageinstallation
import fetchMockLib from 'fetch-mock';

const fetchMock = sandbox();
const fetchMock = fetchMockLib.sandbox();

// config the fetch mock to chain routes (appends the new route to the list of routes)
fetchMock.config.overwriteRoutes = false;
Expand Down
11 changes: 7 additions & 4 deletions src/integrations/ga/GoogleAnalyticsToSplit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { IIntegrationFactoryParams } from '../types';
import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
import { GaToSplit } from './GaToSplit';
import { GoogleAnalyticsToSplitOptions } from './types';

export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions) {
export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): IntegrationFactory {

// GaToSplit integration factory
return (params: IIntegrationFactoryParams) => {
function GoogleAnalyticsToSplitFactory(params: IIntegrationFactoryParams) {
return GaToSplit(options, params);
};
}

GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
return GoogleAnalyticsToSplitFactory;
}
11 changes: 7 additions & 4 deletions src/integrations/ga/SplitToGoogleAnalytics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { IIntegrationFactoryParams } from '../types';
import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
import { SplitToGa } from './SplitToGa';
import { SplitToGoogleAnalyticsOptions } from './types';

export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}) {
export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}): IntegrationFactory {

// SplitToGa integration factory
return (params: IIntegrationFactoryParams) => {
function SplitToGoogleAnalyticsFactory(params: IIntegrationFactoryParams) {
return new SplitToGa(params.settings.log, options);
};
}

SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
return SplitToGoogleAnalyticsFactory;
}
5 changes: 5 additions & 0 deletions src/integrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ export interface IIntegrationFactoryParams {
storage: { events: IEventsCacheBase }
settings: ISettings
}

export type IntegrationFactory = {
readonly type: string
(params: IIntegrationFactoryParams): IIntegration | void
}
2 changes: 1 addition & 1 deletion src/logger/messages/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const codesError: [number, string][] = [
[c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
[c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
[c.ERROR_HTTP, 'Response status is not OK. Status: %s. URL: %s. Message: %s'],
// client status
[c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
[c.ERROR_CLIENT_DESTROYED, '%s: Client has already been destroyed - no calls possible.'],
Expand Down
2 changes: 1 addition & 1 deletion src/logger/messages/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export const codesInfo: [number, string][] = codesWarn.concat([
[c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
[c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
[c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
[c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming (re)connected. Syncing and stopping polling.'],
[c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming connected. Syncing and stopping polling.'],
]);
4 changes: 4 additions & 0 deletions src/logger/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ export interface ILoggerOptions {
export interface ILogger {
setLogLevel(logLevel: LogLevel): void

debug(msg: any): void
debug(msg: string | number, args?: any[]): void

info(msg: any): void
info(msg: string | number, args?: any[]): void

warn(msg: any): void
warn(msg: string | number, args?: any[]): void

error(msg: any): void
error(msg: string | number, args?: any[]): void
}
23 changes: 19 additions & 4 deletions src/sdkClient/__tests__/clientAttributesDecoration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ test('ATTRIBUTES DECORATION / storage', () => {
expect(client.getAttribute('attributeName1')).toEqual(undefined); // It should throw undefined
expect(client.getAttribute('attributeName2')).toEqual('newAttributeValue2'); // It should be equal

client.setAttributes({
expect(client.setAttributes({
'attributeName3': 'attributeValue3',
'attributeName4': 'attributeValue4'
});
})).toEqual(true); // @ts-ignore
expect(client.setAttributes(undefined)).toEqual(false); // @ts-ignore
expect(client.setAttributes(null)).toEqual(false);

expect(client.getAttributes()).toEqual({ attributeName2: 'newAttributeValue2', attributeName3: 'attributeValue3', attributeName4: 'attributeValue4' }); // It should be equal

Expand All @@ -48,7 +50,11 @@ test('ATTRIBUTES DECORATION / storage', () => {

describe('ATTRIBUTES DECORATION / validation', () => {

test('Should return true if it is a valid attributes map without logging any errors', () => {
beforeEach(() => {
loggerMock.mockClear();
});

test('Should return true if it is a valid attributes map without logging any errors and warnings', () => {
const validAttributes = { amIvalid: 'yes', 'are_you_sure': true, howMuch: 10, 'spell': ['1', '0'] };

expect(client.setAttributes(validAttributes)).toEqual(true); // It should return true if it is valid.
Expand All @@ -63,6 +69,8 @@ describe('ATTRIBUTES DECORATION / validation', () => {

expect(Object.keys(client.getAttributes()).length).toEqual(0); // It should be zero after clearing attributes

expect(loggerMock.error).not.toBeCalled(); // no error logs
expect(loggerMock.warn).not.toBeCalled(); // no warning logs
});

test('Should return false if it is an invalid attributes map', () => {
Expand All @@ -82,12 +90,17 @@ describe('ATTRIBUTES DECORATION / validation', () => {
'': 'attributeValue'
};

expect(client.setAttributes(attributes)).toEqual(false); // It should be invalid if the attribute key is not a string
expect(client.setAttributes(attributes)).toEqual(false); // @ts-ignore // It should be invalid if the attribute key is not a string
expect(client.setAttributes(undefined)).toEqual(false); // @ts-ignore // It should be invalid if the attributes param is nullish. Doesn't log an error
expect(client.setAttributes(null)).toEqual(false); // @ts-ignore // It should be invalid if the attributes param is nullish. Doesn't log an error
expect(client.setAttributes('invalid')).toEqual(false); // It should be invalid if the attributes param is not an object

expect(Object.keys(client.getAttributes()).length).toEqual(0); // It should be zero after trying to add an invalid attribute

expect(client.clearAttributes()).toEqual(true);

expect(loggerMock.error).toBeCalledTimes(1); // error logs
expect(loggerMock.warn).toBeCalledTimes(5); // warning logs
});

test('Should return true if attributes map is valid', () => {
Expand All @@ -114,6 +127,8 @@ describe('ATTRIBUTES DECORATION / validation', () => {

expect(client.clearAttributes()).toEqual(true);

expect(loggerMock.error).toBeCalledTimes(0); // no error logs
expect(loggerMock.warn).toBeCalledTimes(0); // no warning logs
});

});
Expand Down
2 changes: 1 addition & 1 deletion src/storages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export interface IStorageFactoryParams {
export type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';

export type IStorageSyncFactory = {
type: StorageType,
readonly type: StorageType,
(params: IStorageFactoryParams): IStorageSync
}

Expand Down
2 changes: 1 addition & 1 deletion src/sync/offline/splitsParser/splitsParserFromFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function splitsParserFromFileFactory(): ISplitsParser {
try {
data = fs.readFileSync(filePath, 'utf-8');
} catch (e) {
log.error(e.message);
log.error(e && (e as Error).message);

return {};
}
Expand Down
Loading