diff --git a/components/notiff/actions/create-notification/create-notification.mjs b/components/notiff/actions/create-notification/create-notification.mjs new file mode 100644 index 0000000000000..3622a6cd5da4e --- /dev/null +++ b/components/notiff/actions/create-notification/create-notification.mjs @@ -0,0 +1,23 @@ +import common from "../../../notiff_io/actions/create-notification/create-notification.mjs"; +import { adjustPropDefinitions } from "../../common/utils.mjs"; +import app from "../../notiff.app.mjs"; + +const props = adjustPropDefinitions(common.props, app); + +export default { + ...common, + key: "notiff-create-notification", + name: "Create Notification", + description: "Send a new notification to a user or system via notiff.io. [See the documentation](https://notiff.io/articles/welcome-to-notiff-getting-started-with-your-notification-center)", + version: "0.0.1", + type: "action", + methods: { + getNotificationSourceId() { + return this.app.$auth.notification_source_id; + }, + }, + props: { + app, + ...props, + }, +}; diff --git a/components/notiff/common/utils.mjs b/components/notiff/common/utils.mjs new file mode 100644 index 0000000000000..da173608f381b --- /dev/null +++ b/components/notiff/common/utils.mjs @@ -0,0 +1,37 @@ +export function adjustPropDefinitions(props, app) { + return Object.fromEntries( + Object.entries(props).map(([ + key, + prop, + ]) => { + const { + propDefinition, ...otherValues + } = prop; + if (propDefinition) { + const [ + , ...otherDefs + ] = propDefinition; + return [ + key, + { + propDefinition: [ + app, + ...otherDefs, + ], + ...otherValues, + }, + ]; + } + return [ + key, + otherValues.type === "app" + ? null + : otherValues, + ]; + }) + .filter(([ + key, + value, + ]) => key != "idNotificationSource" && (value)), + ); +} diff --git a/components/notiff/notiff.app.mjs b/components/notiff/notiff.app.mjs index d5012a1d159c2..05595f8f2dbaf 100644 --- a/components/notiff/notiff.app.mjs +++ b/components/notiff/notiff.app.mjs @@ -1,11 +1,15 @@ +import notiffIo from "../notiff_io/notiff_io.app.mjs"; + export default { + ...notiffIo, type: "app", app: "notiff", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + ...notiffIo.methods, + _headers() { + return { + "Content-Type": "application/json", + }; }, }, }; diff --git a/components/notiff/package.json b/components/notiff/package.json index 251e987d3e8b3..514cf9d005b4e 100644 --- a/components/notiff/package.json +++ b/components/notiff/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notiff", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Notiff Components", "main": "notiff.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/components/notiff_io/actions/create-notification/create-notification.mjs b/components/notiff_io/actions/create-notification/create-notification.mjs new file mode 100644 index 0000000000000..02d903da7c660 --- /dev/null +++ b/components/notiff_io/actions/create-notification/create-notification.mjs @@ -0,0 +1,55 @@ +import app from "../../notiff_io.app.mjs"; + +export default { + key: "notiff_io-create-notification", + name: "Create Notification", + description: "Send a new notification to a user or system via notiff.io. [See the documentation](https://notiff.io/articles/welcome-to-notiff-getting-started-with-your-notification-center)", + version: "0.0.1", + type: "action", + props: { + app, + idNotificationSource: { + type: "string", + label: "ID Notification Source", + description: "To get your Notification Source ID, sign in to Notiff, go to the Settings menu with the gear icon on the top right, click the \"Settings\" option. Copy your Notification Source ID from the list.", + secret: true, + }, + title: { + propDefinition: [ + app, + "title", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + url: { + propDefinition: [ + app, + "url", + ], + }, + }, + methods: { + getNotificationSourceId() { + return this.idNotificationSource; + }, + }, + async run({ $ }) { + const response = await this.app.createNotification({ + $, + data: { + id_notification_source: this.getNotificationSourceId(), + title: this.title, + description: this.description, + url: this.url, + }, + }); + + $.export("$summary", `Notification titled "${this.title}" created successfully!`); + return response; + }, +}; diff --git a/components/notiff_io/notiff_io.app.mjs b/components/notiff_io/notiff_io.app.mjs index fe906e2282bc2..b0ad70e0e8dc6 100644 --- a/components/notiff_io/notiff_io.app.mjs +++ b/components/notiff_io/notiff_io.app.mjs @@ -1,11 +1,49 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "notiff_io", - propDefinitions: {}, + propDefinitions: { + title: { + type: "string", + label: "Title", + description: "The title of the notification.", + }, + description: { + type: "string", + label: "Description", + description: "The content/description of the notification.", + }, + url: { + type: "string", + label: "URL", + description: "The URL associated with the notification.", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://notiff.io/api/1.1/wf"; + }, + _headers() { + return { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + createNotification(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/create_notification", + ...opts, + }); }, }, }; diff --git a/components/notiff_io/package.json b/components/notiff_io/package.json index 4e0a6bd516608..f51bfd41047fc 100644 --- a/components/notiff_io/package.json +++ b/components/notiff_io/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notiff_io", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Notiff (OAuth) Components", "main": "notiff_io.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 795127a8cf399..b9c3630488519 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8708,9 +8708,17 @@ importers: specifier: ^1.3.0 version: 1.6.6 - components/notiff: {} + components/notiff: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 - components/notiff_io: {} + components/notiff_io: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/notion: dependencies: