From ce84445605053beef81a2e36b461dda3459d9d0d Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 15 May 2024 11:35:55 -0300 Subject: [PATCH] Added actions --- .../wiza/actions/create-list/create-list.mjs | 78 +++++++++++++++ .../actions/get-contacts/get-contacts.mjs | 37 +++++++ components/wiza/actions/get-list/get-list.mjs | 28 ++++++ components/wiza/common/constants.mjs | 11 +++ components/wiza/package.json | 7 +- components/wiza/wiza.app.mjs | 97 ++++++++++++++++++- pnpm-lock.yaml | 5 +- 7 files changed, 256 insertions(+), 7 deletions(-) create mode 100644 components/wiza/actions/create-list/create-list.mjs create mode 100644 components/wiza/actions/get-contacts/get-contacts.mjs create mode 100644 components/wiza/actions/get-list/get-list.mjs create mode 100644 components/wiza/common/constants.mjs diff --git a/components/wiza/actions/create-list/create-list.mjs b/components/wiza/actions/create-list/create-list.mjs new file mode 100644 index 0000000000000..26df2cd6a46ee --- /dev/null +++ b/components/wiza/actions/create-list/create-list.mjs @@ -0,0 +1,78 @@ +import app from "../../wiza.app.mjs"; + +export default { + key: "wiza-create-list", + name: "Create List", + description: "Create a list of people to enrich. [See the documentation](https://wiza.co/api-docs#/paths/~1api~1lists/post)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + }, + enrichmentLevel: { + propDefinition: [ + app, + "enrichmentLevel", + ], + }, + acceptGeneric: { + propDefinition: [ + app, + "acceptGeneric", + ], + }, + acceptPersonal: { + propDefinition: [ + app, + "acceptPersonal", + ], + }, + acceptWork: { + propDefinition: [ + app, + "acceptWork", + ], + }, + fullName: { + propDefinition: [ + app, + "fullName", + ], + }, + company: { + propDefinition: [ + app, + "company", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createList({ + $, + data: { + name: this.description, + enrichmentLevel: this.enrichmentLevel, + email_options: { + accept_generic: this.acceptGeneric, + accept_personal: this.acceptPersonal, + accept_work: this.acceptWork, + }, + items: [ + { + full_name: this.fullName, + company: this.company, + }, + ], + }, + }); + + $.export("$summary", `'${response.status.message}', your list's ID is '${response.data.id}'`); + + return response; + }, +}; diff --git a/components/wiza/actions/get-contacts/get-contacts.mjs b/components/wiza/actions/get-contacts/get-contacts.mjs new file mode 100644 index 0000000000000..412bc4f369666 --- /dev/null +++ b/components/wiza/actions/get-contacts/get-contacts.mjs @@ -0,0 +1,37 @@ +import app from "../../wiza.app.mjs"; + +export default { + key: "wiza-get-contacts", + name: "Get Contacts", + description: "Get contacts for a list. [See the documentation](https://wiza.co/api-docs#/paths/~1api~1lists~1%7Bid%7D/get)", + version: "0.0.1", + type: "action", + props: { + app, + id: { + propDefinition: [ + app, + "id", + ], + }, + segment: { + propDefinition: [ + app, + "segment", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getContacts({ + $, + id: this.id, + params: { + segment: this.segment, + }, + }); + + $.export("$summary", "Successfully retrieved the list's contacts"); + + return response; + }, +}; diff --git a/components/wiza/actions/get-list/get-list.mjs b/components/wiza/actions/get-list/get-list.mjs new file mode 100644 index 0000000000000..8178c4dfef8ee --- /dev/null +++ b/components/wiza/actions/get-list/get-list.mjs @@ -0,0 +1,28 @@ +import app from "../../wiza.app.mjs"; + +export default { + key: "wiza-get-list", + name: "Get List", + description: "Get the list with the given id. [See the documentation](https://wiza.co/api-docs#/paths/~1api~1lists~1%7Bid%7D/get)", + version: "0.0.1", + type: "action", + props: { + app, + id: { + propDefinition: [ + app, + "id", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getList({ + $, + id: this.id, + }); + + $.export("$summary", `The status of your list is: '${response.data.status}'`); + + return response; + }, +}; diff --git a/components/wiza/common/constants.mjs b/components/wiza/common/constants.mjs new file mode 100644 index 0000000000000..26fad292c8ab3 --- /dev/null +++ b/components/wiza/common/constants.mjs @@ -0,0 +1,11 @@ +export default { + SEGMENTS: [ + "people", + "valid", + "risky", + ], + ENRICHMENT_LEVELS: [ + "partial", + "full", + ], +}; diff --git a/components/wiza/package.json b/components/wiza/package.json index b0fbf291cada8..b14fd374063dc 100644 --- a/components/wiza/package.json +++ b/components/wiza/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/wiza", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Wiza Components", "main": "wiza.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.5" } -} \ No newline at end of file +} diff --git a/components/wiza/wiza.app.mjs b/components/wiza/wiza.app.mjs index 04884b37d6283..eb16094d1028c 100644 --- a/components/wiza/wiza.app.mjs +++ b/components/wiza/wiza.app.mjs @@ -1,11 +1,100 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "wiza", - propDefinitions: {}, + propDefinitions: { + acceptWork: { + type: "boolean", + label: "Work Email", + description: "Accept professional email address? i.e. 'tim.cooke@apple.com'", + }, + acceptPersonal: { + type: "boolean", + label: "Personal Email", + description: "Accept personal email address? i.e. 'tcooke1960@gmail.com'", + }, + acceptGeneric: { + type: "boolean", + label: "Generic Email", + description: "Accept generic email address? i.e. 'hello@apple.com'", + }, + enrichmentLevel: { + type: "string", + label: "Enrichment Level", + description: "Enrichment level of the list.", + options: constants.ENRICHMENT_LEVELS, + }, + name: { + type: "string", + label: "Name", + description: "Name of the list", + }, + fullName: { + type: "string", + label: "Full Name", + description: "Full name of the contact", + }, + company: { + type: "string", + label: "Company", + description: "Name of the company", + }, + id: { + type: "string", + label: "List ID", + description: "ID of the list", + }, + segment: { + type: "string", + label: "Segment", + description: "Specify the segment of contacts to return", + options: constants.SEGMENTS, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://wiza.co/api"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + async getList({ + args, id, + }) { + return this._makeRequest({ + path: `/lists/${id}`, + ...args, + }); + }, + async getContacts({ + id, ...args + }) { + return this._makeRequest({ + path: `/lists/${id}/contacts`, + ...args, + }); + }, + async createList(args = {}) { + return this._makeRequest({ + method: "post", + path: "/lists", + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e33968d60512f..649e27471149c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9565,7 +9565,10 @@ importers: '@pipedream/platform': 1.5.1 components/wiza: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.5 + dependencies: + '@pipedream/platform': 1.6.5 components/wonderchat: specifiers: {}