-
Notifications
You must be signed in to change notification settings - Fork 59
feat: sends modal event data to modal wrapper for use in hooks #1170
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
Seavenly
merged 14 commits into
feature/DTCRCMERC-3611-modal-lander-v6
from
feature/modal-wrapper-events
Apr 7, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f40050f
sends modal events with data to modal wrapper for use in hooks
danzhaaspaypal abfb667
adds required props to hook event
danzhaaspaypal 58abf9c
refactors onApply for handling in wrapper
danzhaaspaypal 3283443
renames postmessenger event names and refactors
danzhaaspaypal e91a56d
fixes props validation
danzhaaspaypal 71b7c29
corrects offerTypes to offerType
danzhaaspaypal 4551ab3
Merge branch 'feature/DTCRCMERC-3611-modal-lander-v6' of https://gith…
danzhaaspaypal 5593c7b
addresses comments
danzhaaspaypal f0a7ea8
Merge branch 'feature/DTCRCMERC-3611-modal-lander-v6' of https://gith…
danzhaaspaypal 598a95b
Merge branch 'develop' of https://github.com/paypal/paypal-messaging-…
danzhaaspaypal 216de65
Merge branch 'feature/DTCRCMERC-3611-modal-lander-v6' of https://gith…
danzhaaspaypal e366b2a
refactors and addresses comments
danzhaaspaypal e7fd98c
makes message concise
danzhaaspaypal 8ad8237
feat: supports v6 custom close button (#1190)
danzhaaspaypal 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { uniqueID } from '@krakenjs/belter/src'; | ||
|
||
// these constants are defined in PostMessenger | ||
const POSTMESSENGER_EVENT_TYPES = { | ||
ACK: 'ack', | ||
MESSAGE: 'message' | ||
}; | ||
const POSTMESSENGER_ACK_PAYLOAD = { | ||
ok: 'true' | ||
}; | ||
// these constants should maintain parity with MESSAGE_MODAL_EVENT_NAMES in core-web-sdk | ||
export const POSTMESSENGER_EVENT_NAMES = { | ||
CALCULATE: 'paypal-messages-modal-calculate', | ||
CLOSE: 'paypal-messages-modal-close', | ||
SHOW: 'paypal-messages-modal-show' | ||
}; | ||
|
||
export function sendEvent(payload, trustedOrigin) { | ||
if (!trustedOrigin) { | ||
return; | ||
} | ||
|
||
const isTest = process.env.NODE_ENV === 'test'; | ||
const targetWindow = !isTest && window.parent === window ? window.opener : window.parent; | ||
|
||
targetWindow.postMessage(payload, trustedOrigin); | ||
} | ||
|
||
// This function provides data security by preventing accidentally exposing sensitive data; we are adding | ||
// an extra layer of validation here by only allowing explicitly approved fields to be included | ||
function createSafePayload(unscreenedPayload) { | ||
const allowedFields = [ | ||
'linkName' // close event | ||
]; | ||
|
||
const safePayload = {}; | ||
if (unscreenedPayload) { | ||
const entries = Object.entries(unscreenedPayload); | ||
entries.forEach(entry => { | ||
const [key, value] = entry; | ||
if (allowedFields.includes(key)) { | ||
safePayload[key] = value; | ||
} else { | ||
console.warn(`modal hook payload param should be allowlisted if secure: ${key}`); | ||
} | ||
}); | ||
} | ||
|
||
return safePayload; | ||
} | ||
|
||
export function createPostMessengerEvent(typeArg, eventName, eventPayloadArg) { | ||
let type; | ||
let eventPayload; | ||
|
||
if (typeArg === 'ack') { | ||
type = POSTMESSENGER_EVENT_TYPES.ACK; | ||
eventPayload = POSTMESSENGER_ACK_PAYLOAD; | ||
} else if (typeArg === 'message') { | ||
type = POSTMESSENGER_EVENT_TYPES.MESSAGE; | ||
// createSafePayload, only call this if a payload is sent | ||
eventPayload = createSafePayload(eventPayloadArg); | ||
} | ||
|
||
return { | ||
eventName, | ||
id: uniqueID(), | ||
type, | ||
eventPayload: eventPayload || {} | ||
}; | ||
} |
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
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.
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.