@@ -20,12 +20,12 @@ function _interopRequireDefault(obj) {
2020 * options, along with any MC list fields as query params
2121 */
2222
23+ // `param` object avoids CORS issues
24+ // timeout to 3.5s so user isn't waiting forever
25+ // usually occurs w/ privacy plugins enabled
26+ // 3.5s is a bit longer than the time it would take on a Slow 3G connection
2327var subscribeEmailToMailchimp = function subscribeEmailToMailchimp ( url ) {
2428 return new Promise ( function ( resolve , reject ) {
25- // `param` object avoids CORS issues
26- // timeout to 3.5s so user isn't waiting forever
27- // usually occurs w/ privacy plugins enabled
28- // 3.5s is a bit longer than the time it would take on a Slow 3G connection
2929 return ( 0 , _jsonp2 . default ) ( url , { param : 'c' , timeout : 3500 } , function ( err , data ) {
3030 if ( err ) reject ( err ) ;
3131 if ( data ) resolve ( data ) ;
@@ -43,12 +43,12 @@ var subscribeEmailToMailchimp = function subscribeEmailToMailchimp(url) {
4343var convertListFields = function convertListFields ( fields ) {
4444 var queryParams = '' ;
4545 for ( var field in fields ) {
46- // If this is a list group, not user field,
47- // then keep lowercase, as per MC reqs
48- // Read more: https://github.com/benjaminhoffman/gatsby-plugin-mailchimp/blob/master/README.md#groups
49- // NOTE: we use `substring` instead of `startsWith` or `includes` bc of compatability (esp IE)
50- var fieldTransformed = field . substring ( 0 , 6 ) ? field : field . toUpperCase ( ) ;
51- queryParams = queryParams . concat ( '&' + fieldTransformed + '=' + fields [ field ] ) ;
46+ if ( Object . prototype . hasOwnProperty . call ( fields , field ) ) {
47+ // If this is a list group, not user field then keep lowercase, as per MC reqs
48+ // https://github.com/benjaminhoffman/gatsby-plugin-mailchimp/blob/master/README.md#groups
49+ var fieldTransformed = field . substring ( 0 , 6 ) ? field : field . toUpperCase ( ) ;
50+ queryParams = queryParams . concat ( '&' + fieldTransformed + '=' + fields [ field ] ) ;
51+ }
5252 }
5353 return queryParams ;
5454} ;
@@ -72,7 +72,8 @@ var addToMailchimp = function addToMailchimp(email, fields) {
7272 // generate Mailchimp endpoint for jsonp request
7373 // note, we change `/post` to `/post-json`
7474 // otherwise, Mailchomp returns an error
75- var endpoint = window . __GATSBY_PLUGIN_MAILCHIMP_ADDRESS__ . replace ( / \/ p o s t / g, '/post-json' ) ;
75+ // eslint-disable-next-line no-undef
76+ var endpoint = __GATSBY_PLUGIN_MAILCHIMP_ADDRESS__ . replace ( / \/ p o s t / g, '/post-json' ) ;
7677
7778 var queryParams = '&EMAIL=' + emailEncoded + convertListFields ( fields ) ;
7879 var url = '' + endpoint + queryParams ;
0 commit comments