From 9a6b1bb5595f161231db84b0d15f702e8994677f Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 29 Apr 2025 14:05:15 -0300 Subject: [PATCH 1/3] notiff_io init --- .../create-notification.mjs | 48 +++++++++++++ components/notiff_io/notiff_io.app.mjs | 71 ++++++++++++++++++- components/notiff_io/package.json | 2 +- 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 components/notiff_io/actions/create-notification/create-notification.mjs 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..2eac7bedc9e5a --- /dev/null +++ b/components/notiff_io/actions/create-notification/create-notification.mjs @@ -0,0 +1,48 @@ +import notiff_io from "../../notiff_io.app.mjs"; +import { axios } from "@pipedream/platform"; + +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.{{ts}}", + type: "action", + props: { + notiff_io, + idNotificationSource: { + propDefinition: [ + notiff_io, + "idNotificationSource", + ], + }, + title: { + propDefinition: [ + notiff_io, + "title", + ], + }, + description: { + propDefinition: [ + notiff_io, + "description", + ], + }, + url: { + propDefinition: [ + notiff_io, + "url", + ], + }, + }, + async run({ $ }) { + const response = await this.notiff_io.sendNotification({ + idNotificationSource: this.idNotificationSource, + 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..704c53bfb0578 100644 --- a/components/notiff_io/notiff_io.app.mjs +++ b/components/notiff_io/notiff_io.app.mjs @@ -1,11 +1,78 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "notiff_io", - propDefinitions: {}, + propDefinitions: { + idNotificationSource: { + type: "string", + label: "Notification Source ID", + description: "The unique identifier for the notification source.", + async options() { + const sources = await this.listNotificationSources(); + return sources.map((source) => ({ + label: source.title, + value: source.id, + })); + }, + }, + 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"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "GET", path = "/", headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + "Authorization": `Bearer ${this.$auth.api_key}`, + ...headers, + }, + }); + }, + async listNotificationSources(opts = {}) { + return this._makeRequest({ + path: "/list_notification_sources", + ...opts, + }); + }, + async sendNotification({ + idNotificationSource, title, description, url, + }, opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/create_notification", + data: { + id_notification_source: idNotificationSource, + title, + description, + url, + }, + ...opts, + }); + }, }, }; diff --git a/components/notiff_io/package.json b/components/notiff_io/package.json index 4e0a6bd516608..0f8c337d09b75 100644 --- a/components/notiff_io/package.json +++ b/components/notiff_io/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} From f24bc98b5925e1f7d17a65ddedad0e4fc8ff05c8 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 29 Apr 2025 15:19:57 -0300 Subject: [PATCH 2/3] [Components] notiff_io #16263 Actions - Create Notification --- .../create-notification.mjs | 23 +++++++++ components/notiff/common/utils.mjs | 37 ++++++++++++++ components/notiff/notiff.app.mjs | 12 +++-- components/notiff/package.json | 7 ++- .../create-notification.mjs | 41 +++++++++------- components/notiff_io/notiff_io.app.mjs | 49 ++++--------------- components/notiff_io/package.json | 5 +- 7 files changed, 111 insertions(+), 63 deletions(-) create mode 100644 components/notiff/actions/create-notification/create-notification.mjs create mode 100644 components/notiff/common/utils.mjs 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 index 2eac7bedc9e5a..02d903da7c660 100644 --- a/components/notiff_io/actions/create-notification/create-notification.mjs +++ b/components/notiff_io/actions/create-notification/create-notification.mjs @@ -1,48 +1,55 @@ -import notiff_io from "../../notiff_io.app.mjs"; -import { axios } from "@pipedream/platform"; +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.{{ts}}", + version: "0.0.1", type: "action", props: { - notiff_io, + app, idNotificationSource: { - propDefinition: [ - notiff_io, - "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: [ - notiff_io, + app, "title", ], }, description: { propDefinition: [ - notiff_io, + app, "description", ], }, url: { propDefinition: [ - notiff_io, + app, "url", ], }, }, + methods: { + getNotificationSourceId() { + return this.idNotificationSource; + }, + }, async run({ $ }) { - const response = await this.notiff_io.sendNotification({ - idNotificationSource: this.idNotificationSource, - title: this.title, - description: this.description, - url: this.url, + 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`); + $.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 704c53bfb0578..b0ad70e0e8dc6 100644 --- a/components/notiff_io/notiff_io.app.mjs +++ b/components/notiff_io/notiff_io.app.mjs @@ -4,18 +4,6 @@ export default { type: "app", app: "notiff_io", propDefinitions: { - idNotificationSource: { - type: "string", - label: "Notification Source ID", - description: "The unique identifier for the notification source.", - async options() { - const sources = await this.listNotificationSources(); - return sources.map((source) => ({ - label: source.title, - value: source.id, - })); - }, - }, title: { type: "string", label: "Title", @@ -33,44 +21,27 @@ export default { }, }, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); - }, _baseUrl() { return "https://notiff.io/api/1.1/wf"; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "GET", path = "/", headers, ...otherOpts - } = opts; + _headers() { + return { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - "Authorization": `Bearer ${this.$auth.api_key}`, - ...headers, - }, - }); - }, - async listNotificationSources(opts = {}) { - return this._makeRequest({ - path: "/list_notification_sources", + headers: this._headers(), ...opts, }); }, - async sendNotification({ - idNotificationSource, title, description, url, - }, opts = {}) { + createNotification(opts = {}) { return this._makeRequest({ method: "POST", path: "/create_notification", - data: { - id_notification_source: idNotificationSource, - title, - description, - url, - }, ...opts, }); }, diff --git a/components/notiff_io/package.json b/components/notiff_io/package.json index 0f8c337d09b75..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" } } From a4f2ddc0669c5438b9b7b66df40f13e7d6183dbc Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 29 Apr 2025 15:23:04 -0300 Subject: [PATCH 3/3] pnpm update --- pnpm-lock.yaml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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: