From 572de72af34343c3cb608483995a0a348190d100 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 17 Apr 2025 08:28:27 -0300 Subject: [PATCH 1/2] Added actions --- components/goodbits/.gitignore | 3 - .../actions/create-link/create-link.mjs | 56 ++++++++++ .../create-subscriber/create-subscriber.mjs | 42 +++++++ .../update-subscriber-status.mjs | 35 ++++++ components/goodbits/app/goodbits.app.ts | 13 --- components/goodbits/common/constants.mjs | 8 ++ components/goodbits/goodbits.app.mjs | 105 ++++++++++++++++++ components/goodbits/package.json | 8 +- pnpm-lock.yaml | 6 +- 9 files changed, 256 insertions(+), 20 deletions(-) delete mode 100644 components/goodbits/.gitignore create mode 100644 components/goodbits/actions/create-link/create-link.mjs create mode 100644 components/goodbits/actions/create-subscriber/create-subscriber.mjs create mode 100644 components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs delete mode 100644 components/goodbits/app/goodbits.app.ts create mode 100644 components/goodbits/common/constants.mjs create mode 100644 components/goodbits/goodbits.app.mjs diff --git a/components/goodbits/.gitignore b/components/goodbits/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/goodbits/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/goodbits/actions/create-link/create-link.mjs b/components/goodbits/actions/create-link/create-link.mjs new file mode 100644 index 0000000000000..f95fd6d182502 --- /dev/null +++ b/components/goodbits/actions/create-link/create-link.mjs @@ -0,0 +1,56 @@ +import app from "../../goodbits.app.mjs"; + +export default { + key: "goodbits-create-link", + name: "Create Link", + description: "Create a new link. [See the documentation](https://support.goodbits.io/article/115-goodbit-api)", + version: "0.0.1", + type: "action", + props: { + app, + url: { + propDefinition: [ + app, + "url", + ], + }, + title: { + propDefinition: [ + app, + "title", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + fetchRemoteThumbnailUrl: { + propDefinition: [ + app, + "fetchRemoteThumbnailUrl", + ], + }, + imageCandidates: { + propDefinition: [ + app, + "imageCandidates", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createLink({ + $, + data: { + url: this.url, + title: this.title, + description: this.description, + fetch_remote_thumbnail_url: this.fetchRemoteThumbnailUrl, + image_candidates: this.imageCandidates, + }, + }); + $.export("$summary", "Successfully created new link"); + return response; + }, +}; diff --git a/components/goodbits/actions/create-subscriber/create-subscriber.mjs b/components/goodbits/actions/create-subscriber/create-subscriber.mjs new file mode 100644 index 0000000000000..e16053b7af5fc --- /dev/null +++ b/components/goodbits/actions/create-subscriber/create-subscriber.mjs @@ -0,0 +1,42 @@ +import app from "../../goodbits.app.mjs"; + +export default { + key: "goodbits-create-subscriber", + name: "Create Subscriber", + description: "Create a new subscriber. [See the documentation](https://support.goodbits.io/article/115-goodbit-api)", + version: "0.0.1", + type: "action", + props: { + app, + email: { + propDefinition: [ + app, + "email", + ], + }, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + lastName: { + propDefinition: [ + app, + "lastName", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createSubscriber({ + $, + data: { + email: this.email, + first_name: this.firstName, + last_name: this.lastName, + }, + }); + $.export("$summary", "Successfully created new subscriber named"); + return response; + }, +}; diff --git a/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs b/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs new file mode 100644 index 0000000000000..228bf93724cd1 --- /dev/null +++ b/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs @@ -0,0 +1,35 @@ +import app from "../../goodbits.app.mjs"; + +export default { + key: "goodbits-update-subscriber-status", + name: "Update Subscriber Status", + description: "Update the status of a subscriber. [See the documentation](https://support.goodbits.io/article/115-goodbit-api)", + version: "0.0.1", + type: "action", + props: { + app, + email: { + propDefinition: [ + app, + "email", + ], + }, + status: { + propDefinition: [ + app, + "status", + ], + }, + }, + async run({ $ }) { + const response = await this.app.unsubscribeSubscriber({ + $, + email: this.email, + data: { + status: this.status, + }, + }); + $.export("$summary", "Successfully uptated subscriber status"); + return response; + }, +}; diff --git a/components/goodbits/app/goodbits.app.ts b/components/goodbits/app/goodbits.app.ts deleted file mode 100644 index 2749907b5a10e..0000000000000 --- a/components/goodbits/app/goodbits.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "goodbits", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/goodbits/common/constants.mjs b/components/goodbits/common/constants.mjs new file mode 100644 index 0000000000000..30cee0e6e58c6 --- /dev/null +++ b/components/goodbits/common/constants.mjs @@ -0,0 +1,8 @@ +export default { + STATUS_OPTIONS: [ + "unsubscribed", + "cleaned", + "pending", + "deleted", + ], +}; diff --git a/components/goodbits/goodbits.app.mjs b/components/goodbits/goodbits.app.mjs new file mode 100644 index 0000000000000..e08e834af9662 --- /dev/null +++ b/components/goodbits/goodbits.app.mjs @@ -0,0 +1,105 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "goodbits", + propDefinitions: { + email: { + type: "string", + label: "Email", + description: "Subscriber's email address", + }, + firstName: { + type: "string", + label: "First Name", + description: "Subscriber's first name", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "Subscriber's last name", + optional: true, + }, + status: { + type: "string", + label: "Status", + description: "New status of the subscriber", + options: constants.STATUS_OPTIONS, + }, + url: { + type: "string", + label: "URL", + description: "URL of the new link", + }, + title: { + type: "string", + label: "Title", + description: "Title associated with the link", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "Description of the link", + optional: true, + }, + fetchRemoteThumbnailUrl: { + type: "string", + label: "Fetch Remote Thumbnail URL", + description: "URL to fetch a remote thumbnail image", + optional: true, + }, + imageCandidates: { + type: "string", + label: "Image Candidates", + description: "List of candidate image URLs", + optional: true, + }, + }, + methods: { + _baseUrl() { + return "https://app.goodbits.io/api/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `${this.$auth.api_key}`, + ...headers, + }, + }); + }, + async createSubscriber(args = {}) { + return this._makeRequest({ + path: "/subscribers", + method: "post", + ...args, + }); + }, + async unsubscribeSubscriber({ + email, ...args + }) { + return this._makeRequest({ + path: `/subscribers/${email}`, + method: "put", + ...args, + }); + }, + async createLink(args = {}) { + return this._makeRequest({ + path: "/links", + method: "post", + ...args, + }); + }, + }, +}; diff --git a/components/goodbits/package.json b/components/goodbits/package.json index fe37dd75e33f1..e1b6ca580a402 100644 --- a/components/goodbits/package.json +++ b/components/goodbits/package.json @@ -1,16 +1,18 @@ { "name": "@pipedream/goodbits", - "version": "0.0.2", + "version": "0.0.1", "description": "Pipedream Goodbits Components", - "main": "dist/app/goodbits.app.mjs", + "main": "goodbits.app.mjs", "keywords": [ "pipedream", "goodbits" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/goodbits", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b48ed3b40a5d0..47a4050526e38 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5262,7 +5262,11 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/goodbits: {} + components/goodbits: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/goodreads: dependencies: From 01e889170d94542804e27ac9ef2a322af7891484 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 23 Apr 2025 12:04:30 -0300 Subject: [PATCH 2/2] Done requested changes --- .../actions/create-subscriber/create-subscriber.mjs | 10 ++++++---- .../update-subscriber-status.mjs | 6 ++++-- components/goodbits/goodbits.app.mjs | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/goodbits/actions/create-subscriber/create-subscriber.mjs b/components/goodbits/actions/create-subscriber/create-subscriber.mjs index e16053b7af5fc..d05cd8b813255 100644 --- a/components/goodbits/actions/create-subscriber/create-subscriber.mjs +++ b/components/goodbits/actions/create-subscriber/create-subscriber.mjs @@ -31,12 +31,14 @@ export default { const response = await this.app.createSubscriber({ $, data: { - email: this.email, - first_name: this.firstName, - last_name: this.lastName, + subscriber: { + email: this.email, + first_name: this.firstName, + last_name: this.lastName, + }, }, }); - $.export("$summary", "Successfully created new subscriber named"); + $.export("$summary", "Successfully created new subscriber"); return response; }, }; diff --git a/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs b/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs index 228bf93724cd1..d592e90eba3e6 100644 --- a/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs +++ b/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs @@ -22,11 +22,13 @@ export default { }, }, async run({ $ }) { - const response = await this.app.unsubscribeSubscriber({ + const response = await this.app.updateSubscriberStatus({ $, email: this.email, data: { - status: this.status, + subscriber: { + status: this.status, + }, }, }); $.export("$summary", "Successfully uptated subscriber status"); diff --git a/components/goodbits/goodbits.app.mjs b/components/goodbits/goodbits.app.mjs index e08e834af9662..7f84393d4fc7d 100644 --- a/components/goodbits/goodbits.app.mjs +++ b/components/goodbits/goodbits.app.mjs @@ -52,7 +52,7 @@ export default { optional: true, }, imageCandidates: { - type: "string", + type: "string[]", label: "Image Candidates", description: "List of candidate image URLs", optional: true, @@ -85,7 +85,7 @@ export default { ...args, }); }, - async unsubscribeSubscriber({ + async updateSubscriberStatus({ email, ...args }) { return this._makeRequest({