From fb808e1be1ce3ece530a43bb359ace51607d9450 Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Mon, 14 Oct 2024 09:55:36 -0500 Subject: [PATCH] FullEnrich: new action components (#14282) --- .../actions/enrich-contact/enrich-contact.mjs | 108 ++++++++++++++++++ .../get-enrichment-result.mjs | 51 +++++++++ components/fullenrich/fullenrich.app.mjs | 30 ++++- components/fullenrich/package.json | 7 +- pnpm-lock.yaml | 5 +- 5 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 components/fullenrich/actions/enrich-contact/enrich-contact.mjs create mode 100644 components/fullenrich/actions/get-enrichment-result/get-enrichment-result.mjs diff --git a/components/fullenrich/actions/enrich-contact/enrich-contact.mjs b/components/fullenrich/actions/enrich-contact/enrich-contact.mjs new file mode 100644 index 0000000000000..dfedf596bab03 --- /dev/null +++ b/components/fullenrich/actions/enrich-contact/enrich-contact.mjs @@ -0,0 +1,108 @@ +import { ConfigurationError } from "@pipedream/platform"; +import app from "../../fullenrich.app.mjs"; + +export default { + key: "fullenrich-enrich-contact", + name: "Enrich Contact", + description: "Starts the enrichment process for a specified contact. [See the documentation](https://docs.fullenrich.com/startbulk)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + type: "string", + label: "Name", + description: "The name of the action.", + }, + webhookUrl: { + type: "string", + label: "Webhook URL", + description: "The Webhook URL that will be triggered when the enrichment is done.", + optional: true, + }, + firstname: { + type: "string", + label: "First Name", + description: "The first name of the contact to enrich.", + }, + lastname: { + type: "string", + label: "Last Name", + description: "The last name of the contact to enrich.", + }, + domain: { + type: "string", + label: "Domain", + description: "The domain of the contact's company (e.g., example.com). Optional if **Company Name** is provided.", + optional: true, + }, + companyName: { + type: "string", + label: "Company Name", + description: "The name of the contact's company. Optional if a **Domain** is provided.", + optional: true, + }, + linkedinUrl: { + type: "string", + label: "LinkedIn URL", + description: "The LinkedIn URL of the contact to increase the probability of finding emails and phones.", + optional: true, + }, + enrichFields: { + type: "string[]", + label: "Enrich Fields", + description: "The fields to enrich. By default, the action enriches contact emails and phones.", + optional: true, + options: [ + "contact.emails", + "contact.phones", + ], + }, + }, + methods: { + enrichContacts(args = {}) { + return this.app.post({ + path: "/contact/enrich/bulk", + ...args, + }); + }, + }, + async run({ $ }) { + const { + enrichContacts, + name, + webhookUrl, + firstname, + lastname, + domain, + companyName, + linkedinUrl, + enrichFields, + } = this; + + if (!domain && !companyName) { + throw new ConfigurationError("You must provide either a **Domain** or a **Company Name**."); + } + + const response = await enrichContacts({ + $, + data: { + name, + webhook_url: webhookUrl, + datas: [ + { + firstname, + lastname, + domain, + company_name: companyName, + linkedin_url: linkedinUrl, + enrich_fields: enrichFields, + }, + ], + }, + }); + + $.export("$summary", `Successfully started the enrichment process with ID \`${response.enrichment_id}\`.`); + return response; + }, +}; diff --git a/components/fullenrich/actions/get-enrichment-result/get-enrichment-result.mjs b/components/fullenrich/actions/get-enrichment-result/get-enrichment-result.mjs new file mode 100644 index 0000000000000..fceba9975063f --- /dev/null +++ b/components/fullenrich/actions/get-enrichment-result/get-enrichment-result.mjs @@ -0,0 +1,51 @@ +import app from "../../fullenrich.app.mjs"; + +export default { + key: "fullenrich-get-enrichment-result", + name: "Get Enrichment Result", + description: "Get the enrichment result for a specified contact. [See the documentation](https://docs.fullenrich.com/getbulk).", + version: "0.0.1", + type: "action", + props: { + app, + enrichmentId: { + type: "string", + label: "Enrichment ID", + description: "The ID of the enrichment to get the result for.", + }, + forceResults: { + type: "boolean", + label: "Force Results", + description: "This parameter forces the API to return what has been found so far, even if the enrichment is not finished. This may result in missing information and is not recommended for regular use.", + optional: true, + }, + }, + methods: { + getEnrichmentResult({ + enrichmentId, ...args + } = {}) { + return this.app._makeRequest({ + path: `/contact/enrich/bulk/${enrichmentId}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + getEnrichmentResult, + enrichmentId, + forceResults, + } = this; + + const response = await getEnrichmentResult({ + $, + enrichmentId, + params: { + forceResults, + }, + }); + + $.export("$summary", `Successfully fetched enrichment result with ID \`${response.id}\`.`); + return response; + }, +}; diff --git a/components/fullenrich/fullenrich.app.mjs b/components/fullenrich/fullenrich.app.mjs index 45df43e97572a..a491517f68e93 100644 --- a/components/fullenrich/fullenrich.app.mjs +++ b/components/fullenrich/fullenrich.app.mjs @@ -1,11 +1,33 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "fullenrich", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://app.fullenrich.com/api/v1${path}`; + }, + getHeaders(headers) { + return { + "Content-Type": "application/json", + "Authorization": `Bearer ${this.$auth.api_key}`, + ...headers, + }; + }, + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }); + }, + post(args) { + return this._makeRequest({ + method: "POST", + ...args, + }); }, }, }; diff --git a/components/fullenrich/package.json b/components/fullenrich/package.json index bee0c7b5a0743..808b260bd3c1b 100644 --- a/components/fullenrich/package.json +++ b/components/fullenrich/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/fullenrich", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream FullEnrich Components", "main": "fullenrich.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1145af726f4d9..57193cde8027a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3685,7 +3685,10 @@ importers: '@pipedream/platform': 1.5.1 components/fullenrich: - specifiers: {} + specifiers: + '@pipedream/platform': 3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/fullstory: specifiers: