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..d05cd8b813255 --- /dev/null +++ b/components/goodbits/actions/create-subscriber/create-subscriber.mjs @@ -0,0 +1,44 @@ +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: { + subscriber: { + email: this.email, + first_name: this.firstName, + last_name: this.lastName, + }, + }, + }); + $.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 new file mode 100644 index 0000000000000..d592e90eba3e6 --- /dev/null +++ b/components/goodbits/actions/update-subscriber-status/update-subscriber-status.mjs @@ -0,0 +1,37 @@ +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.updateSubscriberStatus({ + $, + email: this.email, + data: { + subscriber: { + 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..7f84393d4fc7d --- /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 updateSubscriberStatus({ + 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 81abb60212716..fb21dbdb85cbd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5277,7 +5277,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: