Skip to content
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

fix: custom validation refactor #11

Merged
merged 7 commits into from Jul 9, 2019

Conversation

YSNIS
Copy link
Contributor

@YSNIS YSNIS commented Jul 3, 2019

No description provided.

demo/index.html Outdated
amount: '500',
style: {
layout: 'custom',
markup: 'https://localhost.paypal.com:8080/custom.html'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably refrain from committing changes to the demo pages, especially with for non-general use-cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm gonna revert this back. For now though I wanted Ryan to have an easily accessible demo page to test the story.

return validated ? markup : '';
})
);
return markupProm.then(markup => markup);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we are accepting any style.markup value. We should probably ensure that a URL is used from paypalobjects or give a blank message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the regex to match htt[s://www.paypalobjects.com

demo/custom.html Outdated
<!--
{"foo":"bar","style":{"ratio":"2x1"}}
-->
<style>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want an example of this in our repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can get reverted back along with the demo page.

partial(objectAssign, { options }), // Object(markup, options)
insertMarkup // Promise<Object(meta)>
)
insertMarkup // Promise<Object(meta)>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
insertMarkup // Promise<Object(meta)>
insertMarkup // Promise<Object(meta, options)>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -56,16 +56,13 @@ const Banner = {

function render(totalOptions) {
const options = validateOptions(totalOptions);
const renderProm = getBannerMarkup(options) // Promise<Object(markup)>
const renderProm = getBannerMarkup(options) // Promise<Object({ markup, options })>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const renderProm = getBannerMarkup(options) // Promise<Object({ markup, options })>
const renderProm = getBannerMarkup(options) // Promise<Object(markup, options)>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


return data;
const bannerOptions = getBannerOptions(template);
options = objectMerge(options, { ...bannerOptions });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a new variable instead of reassigning the options reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Seavenly Seavenly changed the title fix: Custom validation refactor fix: custom validation refactor Jul 3, 2019
function getBannerOptions(markup) {
const annotationsString = markup.match(/^<!--([\s\S]+?)-->/);
if (annotationsString) {
return JSON.parse(annotationsString[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be valuable to wrap this in a try { } catch { } in case the contents of the comment are not valid JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


return data;
const bannerOptions = getBannerOptions(template);
options = objectMerge(options, { ...bannerOptions });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can bannerOptions be passed as-is as the second argument here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return validated ? markup : '';
})
);
return markupProm.then(markup => markup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be return markupProm, or could just return directly without declaring markupProm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return JSON.parse(annotationsString[1]);
try {
const bannerOptions = JSON.parse(annotationsString[1]);
return bannerOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just return JSON.parse(annotationsString[1])?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - remnant of some previous code.

@@ -22,9 +22,12 @@ function fetcher(url) {
}

function getCustomTemplate(styles) {
let markupRegex = /https:\/\/www\.paypalobjects\.com/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it feasible to use String.prototype.startsWith() instead of a regex for this scenario? And for __DEMO__ we can just accept anything since it's for internal use only?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, have we considered how this will work with the customization app since everything is now some form of URL?

@Seavenly Seavenly merged commit b6f5fce into paypal:develop Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants