-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates for splitio/javascript-commons#352
- Loading branch information
1 parent
9dce402
commit bea1e74
Showing
3 changed files
with
4 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} |