This repository has been archived by the owner on Jan 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CM-1105] Refactor how idCookie is stored in the state (#311)
* [CM-1105] Do not store resolved idcookie in state when mode is generated * remove unused params * adjust config * adjust docs * use empty ic param to signal that cookie failed to resolve
- Loading branch information
1 parent
e485130
commit bf1834b
Showing
12 changed files
with
121 additions
and
107 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,23 +1,19 @@ | ||
import { WrappedReadOnlyStorageHandler } from '../handlers/storage-handler' | ||
import { Enricher, IdCookieConfig } from '../types' | ||
import { Enricher, State } from '../types' | ||
|
||
type Input = { idCookie?: IdCookieConfig, peopleVerifiedId?: string } | ||
type Output = { resolvedIdCookie: string | null } | ||
type Input = Pick<State, 'idCookie' | 'peopleVerifiedId'> | ||
type Output = Pick<State, 'resolvedIdCookie'> | ||
|
||
export function enrichIdCookie( | ||
storageHandler: WrappedReadOnlyStorageHandler | ||
): Enricher<Input, Output> { | ||
return state => { | ||
let resolvedIdCookie: string | null | ||
|
||
if (state.idCookie?.mode === 'provided' && state.idCookie?.strategy === 'cookie' && typeof state.idCookie?.name === 'string') { | ||
resolvedIdCookie = storageHandler.getCookie(state.idCookie.name) | ||
} else if (state.idCookie?.mode === 'provided' && state.idCookie?.strategy === 'localStorage' && typeof state.idCookie?.name === 'string') { | ||
resolvedIdCookie = storageHandler.getDataFromLocalStorage(state.idCookie.name) | ||
if (state.idCookie?.strategy === 'cookie' && typeof state.idCookie?.name === 'string') { | ||
return { ...state, resolvedIdCookie: storageHandler.getCookie(state.idCookie.name) } | ||
} else if (state.idCookie?.strategy === 'localStorage' && typeof state.idCookie?.name === 'string') { | ||
return { ...state, resolvedIdCookie: storageHandler.getDataFromLocalStorage(state.idCookie.name) } | ||
} else { | ||
resolvedIdCookie = state.peopleVerifiedId ?? null | ||
return state | ||
} | ||
|
||
return { ...state, resolvedIdCookie } | ||
} | ||
} |
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
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
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
Oops, something went wrong.