@@ -15,7 +15,7 @@ export default {
1515 name : "New Email Received" ,
1616 description : "Emit new event when a new email is received." ,
1717 type : "source" ,
18- version : "0.1.10 " ,
18+ version : "0.1.11 " ,
1919 dedupe : "unique" ,
2020 props : {
2121 gmail,
@@ -166,7 +166,7 @@ export default {
166166 // create topic prop
167167 let topicName = this . topic ;
168168 if ( this . topicType === "new" ) {
169- const authKeyJSON = JSON . parse ( this . serviceAccountKeyJson ) ;
169+ const authKeyJSON = this . getServiceAccountKeyJson ( ) ;
170170 const { project_id : projectId } = authKeyJSON ;
171171 topicName = `projects/${ projectId } /topics/${ this . convertNameToValidPubSubTopicName (
172172 uuidv4 ( ) ,
@@ -317,8 +317,18 @@ export default {
317317 _setLastReceivedTime ( lastReceivedTime ) {
318318 this . db . set ( "lastReceivedTime" , lastReceivedTime ) ;
319319 } ,
320+ getServiceAccountKeyJson ( ) {
321+ try {
322+ return JSON . parse ( this . serviceAccountKeyJson ) ;
323+ } catch ( err ) {
324+ throw new ConfigurationError ( `Error parsing \`Service Account Key JSON\`. Ensure its contents are valid JSON. \`${ err } \`` ) ;
325+ }
326+ } ,
320327 sdkParams ( ) {
321- const authKeyJSON = JSON . parse ( this . serviceAccountKeyJson ) ;
328+ if ( ! this . serviceAccountKeyJson ) {
329+ throw new ConfigurationError ( "Not able to create a webhook or subscribe to topics without configuring a service account. Please reconfigure the trigger type and try again." ) ;
330+ }
331+ const authKeyJSON = this . getServiceAccountKeyJson ( ) ;
322332 const {
323333 project_id : projectId , client_email, private_key,
324334 } = authKeyJSON ;
@@ -332,6 +342,7 @@ export default {
332342 return sdkParams ;
333343 } ,
334344 async getTopics ( ) {
345+
335346 const sdkParams = this . sdkParams ( ) ;
336347 const pubSubClient = new PubSub ( sdkParams ) ;
337348 const topics = ( await pubSubClient . getTopics ( ) ) [ 0 ] ;
0 commit comments