-
Notifications
You must be signed in to change notification settings - Fork 62
feat: Implements Global Session ID #1217
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* eslint-disable eslint-comments/disable-enable-pair, no-else-return */ | ||
import arrayFrom from 'core-js-pure/stable/array/from'; | ||
import { getStorage as getBelterStorage } from '@krakenjs/belter/src'; | ||
import { getStorage as getBelterStorage, uniqueID as createBelterID } from '@krakenjs/belter/src'; | ||
import { SDK_QUERY_KEYS, SDK_SETTINGS } from '@paypal/sdk-constants/src'; | ||
import { | ||
getClientID, | ||
|
@@ -14,6 +14,8 @@ import { | |
getCSPNonce, | ||
getNamespace as getSDKNamespace, | ||
getDefaultNamespace as getDefaultSDKNamespace, | ||
getGlobalSessionID as getSDKGlobalSessionID, | ||
setGlobalSessionID as setSDKGlobalSessionID, | ||
getSessionID as getSDKSessionID, | ||
getStorageID as getSDKStorageID, | ||
getStorageState as getSDKStorageState, | ||
|
@@ -161,6 +163,26 @@ export function getStorage() { | |
return getBelterStorage({ name: getNamespace() }); | ||
} | ||
|
||
// Uses SDK methods to get and set a global session ID | ||
// value will be passed in message_render events | ||
// and used to correlate with button events | ||
export function getOrCreateGlobalSessionID() { | ||
if (__MESSAGES__.__TARGET__ === 'SDK') { | ||
const globalSessionID = getSDKGlobalSessionID(); | ||
|
||
if (globalSessionID) { | ||
return globalSessionID; | ||
} else { | ||
const globalSessionIDValue = createBelterID(); | ||
setSDKGlobalSessionID(globalSessionIDValue); | ||
|
||
return globalSessionIDValue; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can update 171 to use a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Rene, Ive made the update in latest commit. |
||
} | ||
|
||
// Use SDK methods when available, otherwise manually fetch storage via belter | ||
// see: https://github.com/paypal/paypal-sdk-client/blob/master/src/session.js | ||
export function getSessionID() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned we could just leave this as
undefined
. Let's actually just use the same fallback asgetSessionID
, sogetStorage().getSessionID()
. They can be the same value that's fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Nate, Ive made the update.