Skip to content

Commit

Permalink
Revert "Remove 'full' subpackage, since there is not significant diff…
Browse files Browse the repository at this point in the history
…erence with the default 'slim' subpackage"

This reverts commit 23668a9.
  • Loading branch information
EmilianoSanchez committed Oct 31, 2024
1 parent 558dd0a commit 0ee9331
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 20 deletions.
1 change: 0 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- Removed internal ponyfills for the `Map` and `Set` global objects, dropping support for IE and other outdated browsers. The SDK now requires the runtime environment to support these features natively or provide a polyfill.
- Removed the deprecated `GoogleAnalyticsToSplit` and `SplitToGoogleAnalytics` pluggable integration modules, along with the related interfaces in the TypeScript definitions.
- Removed the `LocalhostFromObject` export from the default import (`import { LocalhostFromObject } from '@splitsoftware/splitio-browserjs'`). It is no longer necessary to manually import and configure it in the `sync.localhostMode` option to enable localhost mode.
- Removed the "full" import (`import { SplitFactory } from '@splitsoftware/splitio-browserjs/full'`), since with the removal of `LocalhostFromObject` from the default import, the difference between them is minimal. The "full" import differs only by including the `unfetch` ponyfill to support older browsers.

0.15.0 (September 13, 2024)
- Updated @splitsoftware/splitio-commons package to version 1.17.0 that includes minor updates:
Expand Down
6 changes: 6 additions & 0 deletions full/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"main": "../cjs/full/index.js",
"module": "../esm/full/index.js",
"types": "../types/full/index.d.ts",
"sideEffects": false
}
13 changes: 12 additions & 1 deletion package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"cjs",
"esm",
"src",
"types"
"types",
"full"
],
"scripts": {
"check": "npm run check:lint && npm run check:types && npm run check:version",
Expand Down Expand Up @@ -59,7 +60,8 @@
"homepage": "https://github.com/splitio/javascript-browser-client#readme",
"dependencies": {
"@splitsoftware/splitio-commons": "2.0.0-rc.5",
"tslib": "^2.3.1"
"tslib": "^2.3.1",
"unfetch": "^4.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
Expand Down
2 changes: 1 addition & 1 deletion rollup.ci.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default env => {
*
* Only https://www.npmjs.com/package/rollup-plugin-ts compiles from node_modules, and is used for tests.
*/
createRollupConfig('esm/umd-full.js', 'full'), // umd/split-browser-VERSION.full[.min].js
createRollupConfig('esm/full/umd.js', 'full'), // umd/split-browser-VERSION.full[.min].js
createRollupConfig('esm/umd.js') // umd/split-browser-VERSION[.min].js
];
};
12 changes: 8 additions & 4 deletions src/__tests__/offline/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import tape from 'tape-catch';
import sinon from 'sinon';
import fetchMock from '../testUtils/fetchMock';
import { url } from '../testUtils';
import { SplitFactory, InLocalStorage } from '../../index';
import { SplitFactory, InLocalStorage } from '../../full';
import { SplitFactory as SplitFactorySlim } from '../../';
import { settingsFactory } from '../../settings';

const settings = settingsFactory({ core: { key: 'facundo@split.io' } });
Expand Down Expand Up @@ -87,15 +88,18 @@ tape('Browser offline mode', function (assert) {
sharedUpdateCount++;
});

const factoryReadyFromCache = SplitFactory({ ...config, storage: InLocalStorage() });
const factoriesReadyFromCache = [
SplitFactory({ ...config, storage: InLocalStorage() }),
SplitFactorySlim({ ...config, storage: InLocalStorage() })
];
const configs = [
{ ...config, features: { ...config.features }, storage: InLocalStorage /* invalid */ },
{ ...config },
config,
];
const factories = [
...configs.map(config => SplitFactory(config)),
factoryReadyFromCache
...factoriesReadyFromCache
];

let readyCount = 0, updateCount = 0, readyFromCacheCount = 0;
Expand Down Expand Up @@ -357,7 +361,7 @@ tape('Browser offline mode', function (assert) {
// SDK events on other factory clients
assert.equal(readyCount, factories.length, 'Each factory client should have emitted SDK_READY event once');
assert.equal(updateCount, factories.length - 1, 'Each factory client except one should have emitted SDK_UPDATE event once');
assert.equal(readyFromCacheCount, 2, 'The main and shared client of the factory with LOCALSTORAGE should have emitted SDK_READY_FROM_CACHE event');
assert.equal(readyFromCacheCount, factoriesReadyFromCache.length * 2, 'The main and shared client of the factories with LOCALSTORAGE should have emitted SDK_READY_FROM_CACHE event');

assert.end();
});
Expand Down
7 changes: 7 additions & 0 deletions src/full/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { SplitFactory } from './splitFactory';
export { InLocalStorage } from '@splitsoftware/splitio-commons/src/storages/inLocalStorage/index';
export { ErrorLogger } from '@splitsoftware/splitio-commons/src/logger/browser/ErrorLogger';
export { WarnLogger } from '@splitsoftware/splitio-commons/src/logger/browser/WarnLogger';
export { InfoLogger } from '@splitsoftware/splitio-commons/src/logger/browser/InfoLogger';
export { DebugLogger } from '@splitsoftware/splitio-commons/src/logger/browser/DebugLogger';
export { PluggableStorage } from '@splitsoftware/splitio-commons/src/storages/pluggable';
27 changes: 27 additions & 0 deletions src/full/splitFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import SplitIO from '@splitsoftware/splitio-commons/types/splitio';
import { settingsFactory } from '../settings/full';
import { getModules } from '../platform/getModules';
import { sdkFactory } from '@splitsoftware/splitio-commons/src/sdkFactory/index';
import { ISdkFactoryParams } from '@splitsoftware/splitio-commons/src/sdkFactory/types';
import { getFetch } from '../platform/getFetchFull';
import { getEventSource } from '../platform/getEventSource';
import { EventEmitter } from '@splitsoftware/splitio-commons/src/utils/MinEvents';
import { now } from '@splitsoftware/splitio-commons/src/utils/timeTracker/now/browser';

const platform = { getFetch, getEventSource, EventEmitter, now };

/**
* SplitFactory with pluggable modules for Browser.
* Includes fetch polyfill out-of-the-box.
*
* @param config - configuration object used to instantiate the SDK
* @param __updateModules - optional function that lets redefine internal SDK modules. Use with
* caution since, unlike `config`, this param is not validated neither considered part of the public API.
* @throws Will throw an error if the provided config is invalid.
*/
export function SplitFactory(config: SplitIO.IClientSideSettings, __updateModules?: (modules: ISdkFactoryParams) => void) {
const settings = settingsFactory(config);
const modules = getModules(settings, platform);
if (__updateModules) __updateModules(modules);
return sdkFactory(modules);
}
File renamed without changes.
6 changes: 6 additions & 0 deletions src/platform/getFetchFull.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IFetch } from '@splitsoftware/splitio-commons/src/services/types';
import unfetch from 'unfetch';

export function getFetch() {
return typeof fetch === 'function' ? fetch : unfetch as unknown as IFetch;
}
File renamed without changes.
21 changes: 12 additions & 9 deletions src/settings/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { settingsFactory } from '../index';
import { settingsFactory as slimSettingsFactory } from '../index';
import { settingsFactory as fullSettingsFactory } from '../full';

test('SETTINGS / Consent is overwritable and "GRANTED" by default', () => {
let settings = settingsFactory({});
expect(settings.userConsent).toEqual('GRANTED'); // userConsent defaults to granted if not provided
[slimSettingsFactory, fullSettingsFactory].forEach((settingsFactory) => {
let settings = settingsFactory({});
expect(settings.userConsent).toEqual('GRANTED'); // userConsent defaults to granted if not provided

settings = settingsFactory({ userConsent: 'INVALID-VALUE' });
expect(settings.userConsent).toEqual('GRANTED'); // userConsent defaults to granted if a wrong value is provided
settings = settingsFactory({ userConsent: 'INVALID-VALUE' });
expect(settings.userConsent).toEqual('GRANTED'); // userConsent defaults to granted if a wrong value is provided

settings = settingsFactory({ userConsent: 'UNKNOWN' });
expect(settings.userConsent).toEqual('UNKNOWN'); // userConsent can be overwritten
settings = settingsFactory({ userConsent: 'UNKNOWN' });
expect(settings.userConsent).toEqual('UNKNOWN'); // userConsent can be overwritten

settings = settingsFactory({ userConsent: 'declined' });
expect(settings.userConsent).toEqual('DECLINED'); // userConsent can be overwritten
settings = settingsFactory({ userConsent: 'declined' });
expect(settings.userConsent).toEqual('DECLINED'); // userConsent can be overwritten
});
});
23 changes: 23 additions & 0 deletions src/settings/full.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { settingsValidation } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/index';
import { defaults } from './defaults';
import { validateRuntime } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/runtime';
import { validateStorageCS } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/storage/storageCS';
import { validatePluggableIntegrations } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/integrations/pluggable';
import { validateLogger } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/logger/pluggableLogger';
import { validateConsent } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/consent';

const params = {
defaults,
acceptKey: true, // Client with bound key
runtime: validateRuntime,
storage: validateStorageCS,
integrations: validatePluggableIntegrations,
logger: validateLogger,
consent: validateConsent,
};

export function settingsFactory(config: any) {
const settings = settingsValidation(config, params);

return settings;
}
5 changes: 3 additions & 2 deletions src/splitFactory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type SplitIO from '@splitsoftware/splitio-commons/types/splitio';
import SplitIO from '@splitsoftware/splitio-commons/types/splitio';
import { settingsFactory } from './settings';
import { getModules } from './platform/getModules';
import { sdkFactory } from '@splitsoftware/splitio-commons/src/sdkFactory/index';
import { ISdkFactoryParams } from '@splitsoftware/splitio-commons/src/sdkFactory/types';
import { getFetch } from './platform/getFetch';
import { getFetch } from './platform/getFetchSlim';
import { getEventSource } from './platform/getEventSource';
import { EventEmitter } from '@splitsoftware/splitio-commons/src/utils/MinEvents';
import { now } from '@splitsoftware/splitio-commons/src/utils/timeTracker/now/browser';
Expand All @@ -12,6 +12,7 @@ const platform = { getFetch, getEventSource, EventEmitter, now };

/**
* SplitFactory with pluggable modules for Browser.
* Doesn't include fetch ponyfill out-of-the-box.
*
* @param config - configuration object used to instantiate the SDK
* @param __updateModules - optional function that lets redefine internal SDK modules. Use with
Expand Down
9 changes: 9 additions & 0 deletions ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
* @author Nico Zelaya <nicolas.zelaya@split.io>
*/

import { SplitFactory as SplitFactoryFull, InLocalStorage as InLocalStorageFull, DebugLogger as DebugLoggerFull, InfoLogger as InfoLoggerFull, WarnLogger as WarnLoggerFull, ErrorLogger as ErrorLoggerFull, PluggableStorage as PluggableStorageFull } from '../types/full';
import { SplitFactory, InLocalStorage, DebugLogger, InfoLogger, WarnLogger, ErrorLogger, PluggableStorage } from '../types/index';

// Entry points must export the same objects
let splitFactory = SplitFactory; splitFactory = SplitFactoryFull;
let inLocalStorage = InLocalStorage; inLocalStorage = InLocalStorageFull;
let pluggableStorage = PluggableStorage; pluggableStorage = PluggableStorageFull;

let stringPromise: Promise<string>;
let splitNamesPromise: Promise<SplitIO.SplitNames>;
Expand Down Expand Up @@ -619,6 +624,10 @@ fullBrowserSettings.debug = DebugLogger();
fullBrowserSettings.debug = InfoLogger();
fullBrowserSettings.debug = WarnLogger();
fullBrowserSettings.debug = ErrorLogger();
fullBrowserSettings.debug = DebugLoggerFull();
fullBrowserSettings.debug = InfoLoggerFull();
fullBrowserSettings.debug = WarnLoggerFull();
fullBrowserSettings.debug = ErrorLoggerFull();

// let fullNodeSettings: SplitIO.INodeSettings = {
// core: {
Expand Down
62 changes: 62 additions & 0 deletions types/full/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Declaration file for JavaScript Browser Split Software SDK
// Project: http://www.split.io/
// Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>

import '@splitsoftware/splitio-commons';

export = JsSdk;

declare module JsSdk {
/**
* Full version of the Split.io SDK factory function.
*
* Unlike the default version, it includes a `fetch` polyfill to support old browsers @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#language-support}.
*
* The settings parameter should be an object that complies with the SplitIO.IClientSideSettings or SplitIO.IClientSideAsyncSettings interfaces.
* For more information read the corresponding article: @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#configuration}
*/
export function SplitFactory(settings: SplitIO.IClientSideSettings): SplitIO.ISDK;
export function SplitFactory(settings: SplitIO.IClientSideAsyncSettings): SplitIO.IAsyncSDK;

/**
* Persistent storage based on the LocalStorage Web API for browsers.
*
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#storage}
*/
export function InLocalStorage(options?: SplitIO.InLocalStorageOptions): SplitIO.StorageSyncFactory;

/**
* Pluggable storage to use the SDK in consumer mode.
*
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#sharing-state-with-a-pluggable-storage}
*/
export function PluggableStorage(options: SplitIO.PluggableStorageOptions): SplitIO.StorageAsyncFactory;

/**
* Creates a logger instance that enables descriptive log messages with DEBUG log level when passed in the factory settings.
*
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#logging}
*/
export function DebugLogger(): SplitIO.ILogger;

/**
* Creates a logger instance that enables descriptive log messages with INFO log level when passed in the factory settings.
*
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#logging}
*/
export function InfoLogger(): SplitIO.ILogger;

/**
* Creates a logger instance that enables descriptive log messages with WARN log level when passed in the factory settings.
*
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#logging}
*/
export function WarnLogger(): SplitIO.ILogger;

/**
* Creates a logger instance that enables descriptive log messages with ERROR log level when passed in the factory settings.
*
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#logging}
*/
export function ErrorLogger(): SplitIO.ILogger;
}

0 comments on commit 0ee9331

Please sign in to comment.