1- import gatsbyConfig from '../../gatsby-config'
21import jsonp from 'jsonp'
32import { validate } from 'email-validator'
43
@@ -18,23 +17,6 @@ const subscribeEmailToMailchimp = url => (
1817 } )
1918)
2019
21- /*
22- * parse the plugin options to use in our jsonp request
23- */
24-
25- const getPluginOptions = ( ) => {
26- // find gatsby-mailchimp plugin options (MC list settings)
27- const options = gatsbyConfig . plugins . find (
28- plugin => plugin . resolve === 'gatsby-plugin-mailchimp'
29- ) . options
30-
31- const isString = typeof options . endpoint === 'string'
32- if ( ! isString ) {
33- throw `Mailchimp endpoint required and must be of type string. See repo README for more info.`
34- }
35- return options
36- } ;
37-
3820/*
3921 * build a query string of MC list fields
4022 * ex: '&KEY1=value1&KEY2=value2'
@@ -65,7 +47,10 @@ const addToMailchimp = (email, fields) => {
6547 // generate Mailchimp endpoint for jsonp request
6648 // note, we change `/post` to `/post-json`
6749 // otherwise, Mailchomp returns an error
68- let { endpoint} = getPluginOptions ( )
50+ let { endpoint} = window . __GATSBY_PLUGIN_MAILCHIMP__ || { } ;
51+ if ( ! typeof endpoint === 'string' ) {
52+ return Promise . reject ( `Mailchimp endpoint required and must be of type string. See repo README for more info.` ) ;
53+ }
6954 endpoint = endpoint . replace ( / \/ p o s t / g, '/post-json' )
7055
7156 const queryParams = `&EMAIL=${ emailEncoded } ${ convertListFields ( fields ) } `
0 commit comments