Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Oct 18, 2024
1 parent 9dce402 commit bea1e74
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
2 changes: 0 additions & 2 deletions src/__tests__/offline/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ tape('Browser offline mode', function (assert) {
});

const sdkReadyFromCache = (client) => () => {
assert.equal(factory.settings.storage.type, 'MEMORY', 'In localhost mode, storage must fallback to memory storage');

const clientStatus = client.__getStatus();
assert.equal(clientStatus.isReadyFromCache, true, 'If ready from cache, READY_FROM_CACHE status must be true');
assert.equal(clientStatus.isReady, false, 'READY status must not be set before READY_FROM_CACHE');
Expand Down
7 changes: 2 additions & 5 deletions src/factory/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { sdkManagerFactory } from '@splitsoftware/splitio-commons/src/sdkManager
import { sdkClientMethodCSFactory } from '@splitsoftware/splitio-commons/src/sdkClient/sdkClientMethodCSWithTT';
import { impressionObserverCSFactory } from '@splitsoftware/splitio-commons/src/trackers/impressionObserver/impressionObserverCS';
import { integrationsManagerFactory } from '@splitsoftware/splitio-commons/src/integrations/browser';
import { __InLocalStorageMockFactory } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/storage/storageCS';
import { sdkFactory } from '@splitsoftware/splitio-commons/src/sdkFactory';
import { LOCALHOST_MODE, STORAGE_LOCALSTORAGE } from '@splitsoftware/splitio-commons/src/utils/constants';
import { createUserConsentAPI } from '@splitsoftware/splitio-commons/src/consent/sdkUserConsent';
Expand All @@ -20,10 +19,8 @@ const syncManagerOnlineCSFactory = syncManagerOnlineFactory(pollingManagerCSFact

function getStorage(settings) {
return settings.storage.type === STORAGE_LOCALSTORAGE ?
InLocalStorage(settings.storage)
: settings.storage.__originalType === STORAGE_LOCALSTORAGE ?
__InLocalStorageMockFactory
: InMemoryStorageCSFactory;
InLocalStorage(settings.storage) :
InMemoryStorageCSFactory;
}

/**
Expand Down
18 changes: 2 additions & 16 deletions src/settings/storage/browser.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
import { isLocalStorageAvailable } from '@splitsoftware/splitio-commons/src/utils/env/isLocalStorageAvailable';
import { LOCALHOST_MODE, STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants';
import { STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants';

const STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';

export function validateStorage(settings) {
let {
log,
mode,
storage: {
type,
options = {},
prefix
} = { type: STORAGE_MEMORY },
} = settings;
let __originalType;

const fallbackToMemory = () => {
__originalType = type;
type = STORAGE_MEMORY;
};

// In localhost mode, fallback to Memory storage and track original type to emit SDK_READY_FROM_CACHE if corresponds.
// ATM, other mode settings (e.g., 'consumer') are ignored in client-side API, and so treated as standalone.
if (mode === LOCALHOST_MODE && type === STORAGE_LOCALSTORAGE) {
fallbackToMemory();
}

// If an invalid storage type is provided OR we want to use LOCALSTORAGE and
// it's not available, fallback into MEMORY
if (type !== STORAGE_MEMORY && type !== STORAGE_LOCALSTORAGE ||
type === STORAGE_LOCALSTORAGE && !isLocalStorageAvailable()) {
fallbackToMemory();
type = STORAGE_MEMORY;
log.error('Invalid or unavailable storage. Fallback into MEMORY storage');
}

return {
type,
options,
prefix,
__originalType
};
}

0 comments on commit bea1e74

Please sign in to comment.