From 3b38c33d50be082432b747286eddfea3d3f2bf76 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 4 Mar 2025 19:44:17 -0300 Subject: [PATCH] Adding checks for service account key --- components/gmail/package.json | 2 +- .../new-email-received/new-email-received.mjs | 17 ++++++++++++++--- pnpm-lock.yaml | 3 +-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/components/gmail/package.json b/components/gmail/package.json index 7095b9626eaf5..26fc311aedb71 100644 --- a/components/gmail/package.json +++ b/components/gmail/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/gmail", - "version": "0.2.1", + "version": "0.2.2", "description": "Pipedream Gmail Components", "main": "gmail.app.mjs", "keywords": [ diff --git a/components/gmail/sources/new-email-received/new-email-received.mjs b/components/gmail/sources/new-email-received/new-email-received.mjs index d55c748d8753a..021d5f00b90cb 100644 --- a/components/gmail/sources/new-email-received/new-email-received.mjs +++ b/components/gmail/sources/new-email-received/new-email-received.mjs @@ -15,7 +15,7 @@ export default { name: "New Email Received", description: "Emit new event when a new email is received.", type: "source", - version: "0.1.10", + version: "0.1.11", dedupe: "unique", props: { gmail, @@ -166,7 +166,7 @@ export default { // create topic prop let topicName = this.topic; if (this.topicType === "new") { - const authKeyJSON = JSON.parse(this.serviceAccountKeyJson); + const authKeyJSON = this.getServiceAccountKeyJson(); const { project_id: projectId } = authKeyJSON; topicName = `projects/${projectId}/topics/${this.convertNameToValidPubSubTopicName( uuidv4(), @@ -317,8 +317,18 @@ export default { _setLastReceivedTime(lastReceivedTime) { this.db.set("lastReceivedTime", lastReceivedTime); }, + getServiceAccountKeyJson() { + try { + return JSON.parse(this.serviceAccountKeyJson); + } catch (err) { + throw new ConfigurationError(`Error parsing \`Service Account Key JSON\`. Ensure its contents are valid JSON. \`${err}\``); + } + }, sdkParams() { - const authKeyJSON = JSON.parse(this.serviceAccountKeyJson); + if (!this.serviceAccountKeyJson) { + 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."); + } + const authKeyJSON = this.getServiceAccountKeyJson(); const { project_id: projectId, client_email, private_key, } = authKeyJSON; @@ -332,6 +342,7 @@ export default { return sdkParams; }, async getTopics() { + const sdkParams = this.sdkParams(); const pubSubClient = new PubSub(sdkParams); const topics = (await pubSubClient.getTopics())[0]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8d657cda35aec..24cc81109a565 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5988,8 +5988,7 @@ importers: specifier: ^1.6.0 version: 1.6.6 - components/hr_cloud: - specifiers: {} + components/hr_cloud: {} components/hr_partner: {}