-
Notifications
You must be signed in to change notification settings - Fork 58
feat: disable session cookie/localStorage when noFunctional is set #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jaissica12
merged 15 commits into
development
from
feat/SDKE-91-disable-session-cookie-localStorage-when-noFunctional-is-set
Oct 1, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bfbb1de
feat: disable session cookie/localStorage when noFunctional is set
jaissica12 dd1c4b4
chore: updated test content
jaissica12 4b3f250
Merge remote-tracking branch 'origin/development' into feat/SDKE-91-d…
jaissica12 56e96a2
refactor: added getPrivacyFlag, and updated tests for persistence
jaissica12 da13c32
Merge remote-tracking branch 'origin/development' into feat/SDKE-91-d…
jaissica12 4f98dfa
test: source privacy flag from launcherOptions
jaissica12 a165bec
refactor: move allData in SDKState block
jaissica12 cecb4bc
refactor: remove setProductStorage, restore setLocalStorage and updat…
jaissica12 d76d315
chore: added if block to return early in initializeStorage
jaissica12 be956f9
chore: move nonCurrentUserMPIDs update block
jaissica12 4bb7dff
chore: remove setProductStorage from persistence interface
jaissica12 4fa287f
chore: add line break
jaissica12 5f9bccf
test: updated persistence tests
jaissica12 d721f03
test: updated jest test for persistence
jaissica12 58323e0
fix: update persistence to capture isFirstRun correctly
jaissica12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import Store, { IStore } from '../../src/store'; | ||
| import { IMParticleWebSDKInstance } from '../../src/mp-instance'; | ||
| import { SDKInitConfig } from '../../src/sdkRuntimeModels'; | ||
| import Persistence from '../../src/persistence'; | ||
| import { isObject } from '../../src/utils'; | ||
|
|
||
| describe('Persistence', () => { | ||
| let store: IStore; | ||
| let mockMPInstance: IMParticleWebSDKInstance; | ||
| let persistence: Persistence; | ||
|
|
||
| beforeEach(() => { | ||
| store = {} as IStore; | ||
| mockMPInstance = { | ||
| _Helpers: { | ||
| createMainStorageName: () => 'mprtcl-v4', | ||
| isObject, | ||
| }, | ||
| _NativeSdkHelpers: { | ||
| isWebviewEnabled: () => false, | ||
| }, | ||
| _Store: store, | ||
| Identity: { | ||
| getCurrentUser: jest.fn().mockReturnValue({ | ||
| getMPID: () => 'test-mpid', | ||
| }), | ||
| }, | ||
| Logger: { | ||
| verbose: jest.fn(), | ||
| error: jest.fn(), | ||
| warning: jest.fn(), | ||
| }, | ||
| } as unknown as IMParticleWebSDKInstance; | ||
|
|
||
| Store.call(store, {} as SDKInitConfig, mockMPInstance, 'apikey'); | ||
|
|
||
| store.isLocalStorageAvailable = true; | ||
| store.SDKConfig.useCookieStorage = true; | ||
| store.webviewBridgeEnabled = false; | ||
|
|
||
| persistence = new Persistence(mockMPInstance); | ||
| window.localStorage.removeItem(encodeURIComponent(store.storageName)); | ||
| }); | ||
|
|
||
| describe('#update', () => { | ||
| describe('noFunctional privacy flag set to true', () => { | ||
| beforeEach(() => { | ||
| store.setNoFunctional(true); | ||
| store.webviewBridgeEnabled = false; | ||
| }); | ||
|
|
||
| it('should NOT write to cookie and localStorage when useCookieStorage is true', () => { | ||
| store.SDKConfig.useCookieStorage = true; | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).not.toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).not.toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); | ||
| }); | ||
|
|
||
| it('should NOT write to localStorage when useCookieStorage is false', () => { | ||
| store.SDKConfig.useCookieStorage = false; | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).not.toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).not.toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('noFunctional privacy flag set to false', () => { | ||
| beforeEach(() => { | ||
| store.setNoFunctional(false); | ||
| store.webviewBridgeEnabled = false; | ||
| }); | ||
|
|
||
| it('should write to cookie and localStorage when useCookieStorage is true', () => { | ||
| store.SDKConfig.useCookieStorage = true; | ||
|
|
||
| jest.spyOn(persistence, 'getCookie').mockReturnValue(null); | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('should write to localStorage when useCookieStorage is false', () => { | ||
| store.SDKConfig.useCookieStorage = false; | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).not.toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('noFunctional privacy flag set to false by default', () => { | ||
| beforeEach(() => { | ||
| // default is false | ||
| store.webviewBridgeEnabled = false; | ||
| }); | ||
|
|
||
| it('should write to cookie and localStorage by default when useCookieStorage is true', () => { | ||
|
alexs-mparticle marked this conversation as resolved.
|
||
| store.SDKConfig.useCookieStorage = true; | ||
|
|
||
| jest.spyOn(persistence, 'getCookie').mockReturnValue(null); | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('should write to localStorage by default when useCookieStorage is false', () => { | ||
| store.SDKConfig.useCookieStorage = false; | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).not.toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should NOT write to storage when webviewBridgeEnabled is true', () => { | ||
| store.setNoFunctional(false); | ||
| store.webviewBridgeEnabled = true; | ||
| store.SDKConfig.useCookieStorage = true; | ||
|
|
||
| const setCookieSpy = jest.spyOn(persistence, 'setCookie'); | ||
| const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); | ||
|
|
||
| persistence.update(); | ||
|
|
||
| expect(setCookieSpy).not.toHaveBeenCalled(); | ||
| expect(setLocalStorageSpy).not.toHaveBeenCalled(); | ||
| expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.