-
Notifications
You must be signed in to change notification settings - Fork 782
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
Validate field types sent to mail helper API #822
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
90289ac
Added typechecking in `from` through `content` fields
e10aa0e
Internal fields are written in camel cae instead of dash case
4c55527
Added helper module to validate settings subkeys
db35102
Tracking settings validation
8852bb7
Fix helper function path (oops)
4f64500
Allow either strings or "email objects" in `from` and `reply-to`
37f684b
Strange ESLint error
70fbe2d
Merge branch 'master' into validate-mail-helper-types
thinkingserious 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 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const validate = (parent, parentName, childName, childType) => { | ||
if (typeof parent === 'undefined' || typeof parent[childName] === 'undefined') { | ||
return; | ||
} | ||
if (typeof parent[childName] !== childType) { | ||
throw new Error(`${childType} expected for \`${parentName}.${childName}\``) | ||
} | ||
}; | ||
|
||
module.exports = { | ||
validateMailSettings(settings) { | ||
if (typeof settings !== 'object') { | ||
throw new Error('Object expected for `mailSettings`'); | ||
} | ||
const { | ||
bcc, | ||
bypassListManagement, | ||
footer, | ||
sandboxMode, | ||
spamCheck, | ||
} = settings; | ||
validate(bcc, 'bcc', 'enable', 'boolean'); | ||
validate(bcc, 'bcc', 'email', 'string'); | ||
validate(bypassListManagement, 'bypassListManagement', 'enable', 'boolean'); | ||
validate(footer, 'footer', 'enable', 'boolean'); | ||
validate(footer, 'footer', 'text', 'string'); | ||
validate(footer, 'footer', 'html', 'string'); | ||
validate(sandboxMode, 'sandboxMode', 'enable', 'boolean'); | ||
validate(spamCheck, 'spamCheck', 'enable', 'boolean'); | ||
validate(spamCheck, 'spamCheck', 'threshold', 'number'); | ||
validate(spamCheck, 'spamCheck', 'postToUrl', 'string'); | ||
}, | ||
|
||
validateTrackingSettings(settings) { | ||
if (typeof settings !== 'object') { | ||
throw new Error('Object expected for `mailSettings`'); | ||
} | ||
const { | ||
clickTracking, | ||
openTracking, | ||
subscriptionTracking, | ||
ganalytics, | ||
} = settings; | ||
validate(clickTracking, 'clickTracking', 'enable', 'boolean'); | ||
validate(clickTracking, 'clickTracking', 'enableText', 'boolean'); | ||
validate(openTracking, 'openTracking', 'enable', 'boolean'); | ||
validate(openTracking, 'openTracking', 'substitutionTag', 'string'); | ||
validate(subscriptionTracking, 'subscriptionTracking', 'enable', 'boolean'); | ||
validate(subscriptionTracking, 'subscriptionTracking', 'text', 'string'); | ||
validate(subscriptionTracking, 'subscriptionTracking', 'html', 'string'); | ||
validate(subscriptionTracking, 'subscriptionTracking', 'substitutionTag', 'string'); | ||
validate(ganalytics, 'ganalytics', 'enable', 'boolean'); | ||
validate(ganalytics, 'ganalytics', 'utm_source', 'string'); | ||
validate(ganalytics, 'ganalytics', 'utm_medium', 'string'); | ||
validate(ganalytics, 'ganalytics', 'utm_term', 'string'); | ||
validate(ganalytics, 'ganalytics', 'utm_content', 'string'); | ||
validate(ganalytics, 'ganalytics', 'utm_campaign', 'string'); | ||
}, | ||
}; |
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
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.
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.
The build currently fails ESLint due to an empty code block.
I'm mystified as to why that happens, because my PR doesn't change anything else in this entire file.