Skip to content

Commit f0b7dfe

Browse files
Remove sync.localhostMode option and validation utils
1 parent 4c5f3c6 commit f0b7dfe

File tree

14 files changed

+17
-90
lines changed

14 files changed

+17
-90
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- BREAKING CHANGES:
66
- 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.
77
- Removed the deprecated `GoogleAnalyticsToSplit` and `SplitToGoogleAnalytics` pluggable integration modules, along with the related interfaces in the TypeScript definitions.
8+
- Removed the `LocalhostFromObject` export from the "slim" entrypoint (`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.
89

910
0.15.0 (September 13, 2024)
1011
- Updated @splitsoftware/splitio-commons package to version 1.17.0 that includes minor updates:

src/__tests__/consumer/browser_consumer.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const config = {
3232
}),
3333
sync: {
3434
impressionsMode: 'DEBUG',
35-
// ignored
36-
largeSegmentsEnabled: true,
3735
},
3836
};
3937

src/__tests__/consumer/browser_consumer_partial.spec.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ const config = {
3333
events: 'https://events.baseurl/impressionsSuite',
3434
telemetry: 'https://telemetry.baseurl/impressionsSuite'
3535
},
36-
sync: {
37-
// ignored
38-
largeSegmentsEnabled: true,
39-
},
4036
};
4137

4238
tape('Browser Consumer Partial mode with pluggable storage', function (t) {

src/__tests__/offline/browser.spec.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sinon from 'sinon';
33
import fetchMock from '../testUtils/fetchMock';
44
import { url } from '../testUtils';
55
import { SplitFactory, InLocalStorage } from '../../full';
6-
import { SplitFactory as SplitFactorySlim, LocalhostFromObject } from '../../';
6+
import { SplitFactory as SplitFactorySlim } from '../../';
77
import { settingsFactory } from '../../settings';
88

99
const settings = settingsFactory({ core: { key: 'facundo@split.io' } });
@@ -61,10 +61,6 @@ tape('Browser offline mode', function (assert) {
6161
readyTimeout: 0.001
6262
},
6363
features: originalFeaturesMap,
64-
sync: {
65-
// ignored
66-
largeSegmentsEnabled: true,
67-
}
6864
};
6965
const factory = SplitFactory(config);
7066
const manager = factory.manager();
@@ -94,24 +90,19 @@ tape('Browser offline mode', function (assert) {
9490

9591
const factoriesReadyFromCache = [
9692
SplitFactory({ ...config, storage: InLocalStorage() }),
97-
SplitFactorySlim({ ...config, storage: InLocalStorage(), sync: { localhostMode: LocalhostFromObject() } }) // slim factory requires localhostFromObject module
93+
SplitFactorySlim({ ...config, storage: InLocalStorage() })
9894
];
9995
const configs = [
100-
{ ...config, features: { ...config.features }, storage: InLocalStorage /* invalid */, sync: { localhostMode: LocalhostFromObject /* invalid */ } },
96+
{ ...config, features: { ...config.features }, storage: InLocalStorage /* invalid */ },
10197
{ ...config },
10298
config,
10399
];
104-
const factoriesReady = [
100+
const factories = [
105101
...configs.map(config => SplitFactory(config)),
106102
...factoriesReadyFromCache
107103
];
108-
const factoriesTimeout = [ // slim factory without a valid localhostFromObject module will timeout
109-
SplitFactorySlim(config),
110-
SplitFactorySlim({ ...config, sync: { localhostMode: LocalhostFromObject /* invalid */ } }),
111-
];
112-
const factories = [...factoriesReady, ...factoriesTimeout];
113104

114-
let readyCount = 0, updateCount = 0, readyFromCacheCount = 0, timeoutCount = 0;
105+
let readyCount = 0, updateCount = 0, readyFromCacheCount = 0;
115106

116107
for (let i = 0; i < factories.length; i++) {
117108
const factory = factories[i], client = factory.client(), manager = factory.manager(), client2 = factory.client('other');
@@ -127,8 +118,7 @@ tape('Browser offline mode', function (assert) {
127118
updateCount++;
128119
});
129120
client.on(client.Event.SDK_READY_TIMED_OUT, () => {
130-
assert.equal(factory.settings.sync.localhostMode, undefined);
131-
timeoutCount++;
121+
assert.fail('Should not emit SDK_READY_TIMED_OUT event');
132122
});
133123

134124
const sdkReadyFromCache = (client) => () => {
@@ -253,8 +243,8 @@ tape('Browser offline mode', function (assert) {
253243
};
254244

255245
// Update the features in all remaining factories except the last one
256-
for (let i = 1; i < factoriesReady.length - 1; i++) {
257-
factoriesReady[i].settings.features = factory.settings.features;
246+
for (let i = 1; i < factories.length - 1; i++) {
247+
factories[i].settings.features = factory.settings.features;
258248
}
259249

260250
// Assigning a new object to the features property in the config object doesn't trigger an update
@@ -369,10 +359,9 @@ tape('Browser offline mode', function (assert) {
369359
assert.equal(sharedUpdateCount, 1, 'Shared client should have emitted SDK_UPDATE event once');
370360

371361
// SDK events on other factory clients
372-
assert.equal(readyCount, factoriesReady.length, 'Each factory client should have emitted SDK_READY event once');
373-
assert.equal(updateCount, factoriesReady.length - 1, 'Each factory client except one should have emitted SDK_UPDATE event once');
362+
assert.equal(readyCount, factories.length, 'Each factory client should have emitted SDK_READY event once');
363+
assert.equal(updateCount, factories.length - 1, 'Each factory client except one should have emitted SDK_UPDATE event once');
374364
assert.equal(readyFromCacheCount, factoriesReadyFromCache.length * 2, 'The main and shared client of the factories with LOCALSTORAGE should have emitted SDK_READY_FROM_CACHE event');
375-
assert.equal(timeoutCount, factoriesTimeout.length, 'The wrongly configured slim factories should have emitted SDK_READY_TIMED_OUT event');
376365

377366
assert.end();
378367
});

src/full/splitFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const platform = { getFetch, getEventSource, EventEmitter, now };
1212

1313
/**
1414
* SplitFactory with pluggable modules for Browser.
15-
* Includes localhost mode and fetch polyfill out-of-the-box.
15+
* Includes fetch polyfill out-of-the-box.
1616
*
1717
* @param config configuration object used to instantiate the SDK
1818
* @param __updateModules optional function that lets redefine internal SDK modules. Use with

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ export { ErrorLogger } from '@splitsoftware/splitio-commons/src/logger/browser/E
44
export { WarnLogger } from '@splitsoftware/splitio-commons/src/logger/browser/WarnLogger';
55
export { InfoLogger } from '@splitsoftware/splitio-commons/src/logger/browser/InfoLogger';
66
export { DebugLogger } from '@splitsoftware/splitio-commons/src/logger/browser/DebugLogger';
7-
export { LocalhostFromObject } from '@splitsoftware/splitio-commons/src/sync/offline/LocalhostFromObject';
87
export { PluggableStorage } from '@splitsoftware/splitio-commons/src/storages/pluggable';

src/platform/getModules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { sdkClientMethodCSFactory } from '@splitsoftware/splitio-commons/src/sdk
77
import { BrowserSignalListener } from '@splitsoftware/splitio-commons/src/listeners/browser';
88
import { impressionObserverCSFactory } from '@splitsoftware/splitio-commons/src/trackers/impressionObserver/impressionObserverCS';
99
import { pluggableIntegrationsManagerFactory } from '@splitsoftware/splitio-commons/src/integrations/pluggable';
10-
1110
import { IPlatform, ISdkFactoryParams } from '@splitsoftware/splitio-commons/src/sdkFactory/types';
1211
import { ISettings } from '@splitsoftware/splitio-commons/src/types';
1312
import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE, LOCALHOST_MODE } from '@splitsoftware/splitio-commons/src/utils/constants';
1413
import { createUserConsentAPI } from '@splitsoftware/splitio-commons/src/consent/sdkUserConsent';
14+
import { localhostFromObjectFactory } from '@splitsoftware/splitio-commons/src/sync/offline/LocalhostFromObject';
1515

1616
let syncManagerStandaloneFactory: ISdkFactoryParams['syncManagerFactory'];
1717
let syncManagerSubmittersFactory: ISdkFactoryParams['syncManagerFactory'];
@@ -51,7 +51,7 @@ export function getModules(settings: ISettings, platform: IPlatform): ISdkFactor
5151
switch (settings.mode) {
5252
case LOCALHOST_MODE:
5353
modules.splitApiFactory = undefined;
54-
modules.syncManagerFactory = settings.sync.localhostMode;
54+
modules.syncManagerFactory = localhostFromObjectFactory;
5555
modules.SignalListener = undefined;
5656
break;
5757
case CONSUMER_MODE:

src/settings/full.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { validateRuntime } from '@splitsoftware/splitio-commons/src/utils/settin
44
import { validateStorageCS } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/storage/storageCS';
55
import { validatePluggableIntegrations } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/integrations/pluggable';
66
import { validateLogger } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/logger/pluggableLogger';
7-
import { validateLocalhostWithDefault } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/localhost/builtin';
87
import { validateConsent } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/consent';
9-
import { STANDALONE_MODE } from '@splitsoftware/splitio-commons/src/utils/constants';
108

119
const params = {
1210
defaults,
@@ -15,15 +13,11 @@ const params = {
1513
storage: validateStorageCS,
1614
integrations: validatePluggableIntegrations,
1715
logger: validateLogger,
18-
localhost: validateLocalhostWithDefault, // Full SplitFactory provides a default localhost module, except a valid one is provided
1916
consent: validateConsent,
2017
};
2118

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

25-
// @ts-ignore, Override in localhost and consumer modes to emit SDK_READY event
26-
if (settings.mode !== STANDALONE_MODE) settings.sync.largeSegmentsEnabled = false;
27-
2822
return settings;
2923
}

src/settings/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { validateRuntime } from '@splitsoftware/splitio-commons/src/utils/settin
44
import { validateStorageCS } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/storage/storageCS';
55
import { validatePluggableIntegrations } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/integrations/pluggable';
66
import { validateLogger } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/logger/pluggableLogger';
7-
import { validateLocalhost } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/localhost/pluggable';
87
import { validateConsent } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/consent';
9-
import { STANDALONE_MODE } from '@splitsoftware/splitio-commons/src/utils/constants';
108

119
const params = {
1210
defaults,
@@ -15,15 +13,11 @@ const params = {
1513
storage: validateStorageCS,
1614
integrations: validatePluggableIntegrations,
1715
logger: validateLogger,
18-
localhost: validateLocalhost, // Slim SplitFactory validates that the localhost module is passed in localhost mode
1916
consent: validateConsent,
2017
};
2118

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

25-
// @ts-ignore, Override in localhost and consumer modes to emit SDK_READY event
26-
if (settings.mode !== STANDALONE_MODE) settings.sync.largeSegmentsEnabled = false;
27-
2822
return settings;
2923
}

src/splitFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const platform = { getFetch, getEventSource, EventEmitter, now };
1212

1313
/**
1414
* Slim SplitFactory with pluggable modules for Browser.
15-
* Doesn't include localhost mode and fetch ponyfill out-of-the-box.
15+
* Doesn't include fetch ponyfill out-of-the-box.
1616
*
1717
* @param config configuration object used to instantiate the SDK
1818
* @param __updateModules optional function that lets redefine internal SDK modules. Use with

ts-tests/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
import { SplitFactory as SplitFactoryFull, InLocalStorage as InLocalStorageFull, DebugLogger as DebugLoggerFull, InfoLogger as InfoLoggerFull, WarnLogger as WarnLoggerFull, ErrorLogger as ErrorLoggerFull, PluggableStorage as PluggableStorageFull } from '@splitsoftware/splitio-browserjs/full';
15-
import { SplitFactory, InLocalStorage, DebugLogger, InfoLogger, WarnLogger, ErrorLogger, LocalhostFromObject, PluggableStorage } from '@splitsoftware/splitio-browserjs';
15+
import { SplitFactory, InLocalStorage, DebugLogger, InfoLogger, WarnLogger, ErrorLogger, PluggableStorage } from '@splitsoftware/splitio-browserjs';
1616

1717
// Entry points must export the same objects
1818
let splitFactory = SplitFactory; splitFactory = SplitFactoryFull;
@@ -563,7 +563,6 @@ let fullBrowserSettings: SplitIO.IBrowserSettings = {
563563
sync: {
564564
splitFilters: splitFilters,
565565
impressionsMode: 'DEBUG',
566-
localhostMode: LocalhostFromObject(),
567566
enabled: true,
568567
requestOptions: {
569568
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' }; },

types/full/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ declare module JsSdk {
1010
* Full version of the Split.io SDK factory function.
1111
*
1212
* Unlike the slim version, it doesn't require a 'fetch' polyfill to support old browsers @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#language-support}.
13-
* and includes localhost mode out-of-the-box @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode}.
1413
*
1514
* The settings parameter should be an object that complies with the SplitIO.IBrowserSettings.
1615
* For more information read the corresponding article: @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#configuration}

types/index.d.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ declare module JsSdk {
99
/**
1010
* Slim version of the Split.io SDK factory function.
1111
*
12-
* Recommended to use for bundle size reduction in production, since it doesn't include a 'fetch' polyfill and localhost mode out-of-the-box
13-
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode}.
12+
* Recommended to use for bundle size reduction in production, since it doesn't include a 'fetch' polyfill out-of-the-box
1413
*
1514
* The settings parameter should be an object that complies with the SplitIO.IBrowserSettings.
1615
* For more information read the corresponding article: @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#configuration}
@@ -59,12 +58,4 @@ declare module JsSdk {
5958
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#logging}
6059
*/
6160
export function ErrorLogger(): SplitIO.ILogger;
62-
63-
/**
64-
* Required to enable localhost mode when importing the SDK from the slim entry point of the library.
65-
* It uses the mocked features map defined in the 'features' config object.
66-
*
67-
* @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode}
68-
*/
69-
export function LocalhostFromObject(): SplitIO.LocalhostFactory;
7061
}

types/splitio.d.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ interface ISettings {
9191
impressionsMode: SplitIO.ImpressionsMode,
9292
enabled: boolean,
9393
flagSpecVersion: string,
94-
localhostMode?: SplitIO.LocalhostFactory,
9594
requestOptions?: {
9695
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
9796
},
@@ -225,25 +224,6 @@ interface ISharedSettings {
225224
* @default 'OPTIMIZED'
226225
*/
227226
impressionsMode?: SplitIO.ImpressionsMode,
228-
/**
229-
* Defines the factory function to instantiate the SDK in localhost mode.
230-
*
231-
* NOTE: this is only required if using the slim entry point of the library to init the SDK in localhost mode.
232-
*
233-
* For more information see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode}
234-
*
235-
* Example:
236-
* ```typescript
237-
* SplitFactory({
238-
* ...
239-
* sync: {
240-
* localhostMode: LocalhostFromObject()
241-
* }
242-
* })
243-
* ```
244-
* @property {Object} localhostMode
245-
*/
246-
localhostMode?: SplitIO.LocalhostFactory
247227
/**
248228
* Controls the SDK continuous synchronization flags.
249229
*
@@ -471,11 +451,6 @@ declare namespace SplitIO {
471451
type MockedFeaturesMap = {
472452
[featureName: string]: string | TreatmentWithConfig
473453
};
474-
/**
475-
* Localhost types.
476-
* @typedef {string} LocalhostType
477-
*/
478-
type LocalhostType = 'LocalhostFromObject'
479454
/**
480455
* Object with information about an impression. It contains the generated impression DTO as well as
481456
* complementary information around where and how it was generated in that way.
@@ -624,14 +599,6 @@ declare namespace SplitIO {
624599
*/
625600
wrapper: Object
626601
}
627-
/**
628-
* Localhost mode factory.
629-
* Its interface details are not part of the public API.
630-
*/
631-
type LocalhostFactory = {
632-
readonly type: LocalhostType
633-
(params: {}): {}
634-
}
635602
/**
636603
* Impression listener interface. This is the interface that needs to be implemented
637604
* by the element you provide to the SDK as impression listener.

0 commit comments

Comments
 (0)