diff --git a/components/alerty/actions/notify-devices/notify-devices.mjs b/components/alerty/actions/notify-devices/notify-devices.mjs new file mode 100644 index 0000000000000..7d1f1da5ef030 --- /dev/null +++ b/components/alerty/actions/notify-devices/notify-devices.mjs @@ -0,0 +1,73 @@ +import alerty from "../../alerty.app.mjs"; +import { URGENCY_OPTIONS } from "../../common/constants.mjs"; +import { parseObject } from "../../common/utils.mjs"; + +export default { + key: "alerty-notify-devices", + name: "Notify Devices", + description: "Sends a notification to active devices. [See the documentation](https://alerty.dev/api/notify)", + version: "0.0.1", + type: "action", + props: { + alerty, + message: { + type: "string", + label: "Message", + description: "The message to be included in the push notification.", + }, + title: { + type: "string", + label: "Title", + description: "Title for your notification message.", + optional: true, + }, + image: { + type: "string", + label: "Image URL", + description: "URL of an image to be displayed in the notification.", + optional: true, + }, + icon: { + type: "string", + label: "Icon URL", + description: "URL of an image to be used as an icon by the notification. Default: Alerty Logo", + optional: true, + }, + deviceId: { + type: "string[]", + label: "Device ID", + description: "Specific device IDs to send the notification to. If no Device Id is included, the push message will be sent to all active devices on your account.", + optional: true, + }, + urgency: { + type: "string", + label: "Urgency", + description: "Urgency of the notification. Default: very-low", + options: URGENCY_OPTIONS, + optional: true, + }, + actions: { + type: "string[]", + label: "Actions", + description: "Actions for the notification, each item should be a JSON string. Example: { \"action\": \"https://example.com\", \"title\": \"Open Site\", \"icon\": \"https://example.com/icon.png\" }", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.alerty.makeRequest({ + $, + data: { + message: this.message, + title: this.title, + image: this.image, + icon: this.icon, + device_id: parseObject(this.deviceId), + urgency: this.urgency, + actions: parseObject(this.actions), + }, + }); + + $.export("$summary", `Notification sent with message: "${this.message}"`); + return response; + }, +}; diff --git a/components/alerty/alerty.app.mjs b/components/alerty/alerty.app.mjs index 72550afefbecc..f478429ee343b 100644 --- a/components/alerty/alerty.app.mjs +++ b/components/alerty/alerty.app.mjs @@ -1,11 +1,26 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "alerty", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `${this.$auth.notification_url}`; + }, + _headers() { + return { + Authorization: `Bearer ${this.$auth.api_key}`, + }; + }, + makeRequest({ + $ = this, ...opts + }) { + return axios($, { + method: "POST", + url: this._baseUrl(), + headers: this._headers(), + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/alerty/common/constants.mjs b/components/alerty/common/constants.mjs new file mode 100644 index 0000000000000..3d30edf5f831a --- /dev/null +++ b/components/alerty/common/constants.mjs @@ -0,0 +1,6 @@ +export const URGENCY_OPTIONS = [ + "very-low", + "low", + "normal", + "high", +]; diff --git a/components/alerty/common/utils.mjs b/components/alerty/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/alerty/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/alerty/package.json b/components/alerty/package.json index 6ae53e7dd33ef..eaadf692bfa3a 100644 --- a/components/alerty/package.json +++ b/components/alerty/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/alerty", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Alerty Components", "main": "alerty.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.1" } -} \ No newline at end of file +} + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ba3398819357..2cca41acfd6f4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -438,7 +438,10 @@ importers: specifiers: {} components/alerty: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.1 + dependencies: + '@pipedream/platform': 3.0.1 components/algodocs: specifiers: {} @@ -12647,55 +12650,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: - resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sts': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sts' - - aws-crt - dev: false - /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -12931,7 +12885,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 + '@aws-sdk/client-sso-oidc': 3.600.0 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -12973,6 +12927,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: + resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' + - aws-crt + dev: false + /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17271,10 +17274,10 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 - '@pipedream/platform': 1.6.5 + '@pipedream/platform': 1.6.6 adm-zip: 0.5.10 dedent: 1.5.1 mailparser: 3.6.6 @@ -17291,7 +17294,7 @@ packages: resolution: {integrity: sha512-r0H0A1HsSEDVTPVSvK4XXcExEeUnkpIqLMNVM2aLh1bwdOblTS1sxLZ9mz/7DwAr8wRNCoW6zlXZBEhexIyyAg==} dependencies: '@googleapis/drive': 2.4.0 - '@pipedream/platform': 1.6.5 + '@pipedream/platform': 1.6.6 cron-parser: 4.9.0 lodash: 4.17.21 mime-db: 1.52.0 @@ -17305,7 +17308,7 @@ packages: /@pipedream/helper_functions/0.3.12: resolution: {integrity: sha512-0n0kKCdrQQWOW275gDHBu0EUAdNssEzT3LLHcOTlzoTXP/V9Ue0VVTmtLDiDdaF9W3a4e2++tICFoVSGSyoMew==} dependencies: - '@pipedream/platform': 1.6.5 + '@pipedream/platform': 1.6.6 streamifier: 0.1.1 xml-js: 1.6.11 transitivePeerDependencies: @@ -21913,7 +21916,7 @@ packages: /axios/0.24.0: resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==} dependencies: - follow-redirects: 1.15.6 + follow-redirects: 1.15.9 transitivePeerDependencies: - debug dev: false @@ -21929,7 +21932,7 @@ packages: /axios/0.26.1: resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} dependencies: - follow-redirects: 1.15.6 + follow-redirects: 1.15.9 transitivePeerDependencies: - debug dev: false @@ -21946,7 +21949,7 @@ packages: /axios/1.4.0: resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==} dependencies: - follow-redirects: 1.15.6 + follow-redirects: 1.15.9 form-data: 4.0.0 proxy-from-env: 1.1.0 transitivePeerDependencies: @@ -21956,7 +21959,7 @@ packages: /axios/1.5.0: resolution: {integrity: sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==} dependencies: - follow-redirects: 1.15.6 + follow-redirects: 1.15.9 form-data: 4.0.0 proxy-from-env: 1.1.0 transitivePeerDependencies: @@ -22005,7 +22008,7 @@ packages: /axios/1.6.5_debug@3.2.7: resolution: {integrity: sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==} dependencies: - follow-redirects: 1.15.6_debug@3.2.7 + follow-redirects: 1.15.9_debug@3.2.7 form-data: 4.0.0 proxy-from-env: 1.1.0 transitivePeerDependencies: @@ -25230,19 +25233,17 @@ packages: optional: true dev: false - /follow-redirects/1.15.6_debug@3.2.7: - resolution: {integrity: sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==} + /follow-redirects/1.15.9: + resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==} engines: {node: '>=4.0'} peerDependencies: debug: '*' peerDependenciesMeta: debug: optional: true - dependencies: - debug: 3.2.7 dev: false - /follow-redirects/1.15.9: + /follow-redirects/1.15.9_debug@3.2.7: resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==} engines: {node: '>=4.0'} peerDependencies: @@ -25250,6 +25251,8 @@ packages: peerDependenciesMeta: debug: optional: true + dependencies: + debug: 3.2.7 dev: false /follow-redirects/1.5.10: