diff --git a/components/opsgenie/.gitignore b/components/opsgenie/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/opsgenie/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/opsgenie/actions/create-alert/create-alert.mjs b/components/opsgenie/actions/create-alert/create-alert.mjs new file mode 100644 index 0000000000000..59f06963bf366 --- /dev/null +++ b/components/opsgenie/actions/create-alert/create-alert.mjs @@ -0,0 +1,65 @@ +import app from "../../opsgenie.app.mjs"; + +export default { + key: "opsgenie-create-alert", + name: "Create Alert", + description: "Send a new Alert for processing. [See the documentation](https://www.postman.com/api-evangelist/opsgenie/request/zuj17nj/create-alert)", + version: "0.0.1", + type: "action", + props: { + app, + user: { + propDefinition: [ + app, + "user", + ], + }, + message: { + propDefinition: [ + app, + "message", + ], + }, + note: { + propDefinition: [ + app, + "note", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + tags: { + propDefinition: [ + app, + "tags", + ], + }, + priority: { + propDefinition: [ + app, + "priority", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createAlert({ + $, + data: { + message: this.message, + user: this.user, + note: this.note, + description: this.description, + tags: this.tags, + priority: this.priority, + }, + }); + + $.export("$summary", `Successfully sent a new alert for processing. The alert ID can be used to check the request status: '${response.requestId}'`); + + return response; + }, +}; diff --git a/components/opsgenie/actions/get-alert-status/get-alert-status.mjs b/components/opsgenie/actions/get-alert-status/get-alert-status.mjs new file mode 100644 index 0000000000000..dba3c52e89a90 --- /dev/null +++ b/components/opsgenie/actions/get-alert-status/get-alert-status.mjs @@ -0,0 +1,28 @@ +import app from "../../opsgenie.app.mjs"; + +export default { + key: "opsgenie-get-alert-status", + name: "Get Alert Status", + description: "Get the status of the alert with the specified ID. [See the documentation](https://www.postman.com/api-evangelist/opsgenie/request/03tcghu/get-request-status-of-alert)", + version: "0.0.1", + type: "action", + props: { + app, + requestId: { + propDefinition: [ + app, + "requestId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getAlertStatus({ + $, + requestId: this.requestId, + }); + + $.export("$summary", `Request processing status: '${response.data.status}'`); + + return response; + }, +}; diff --git a/components/opsgenie/app/opsgenie.app.ts b/components/opsgenie/app/opsgenie.app.ts deleted file mode 100644 index e7a1f2b97e51e..0000000000000 --- a/components/opsgenie/app/opsgenie.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "opsgenie", - 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/opsgenie/common/constants.mjs b/components/opsgenie/common/constants.mjs new file mode 100644 index 0000000000000..6ff20bbfd8cd9 --- /dev/null +++ b/components/opsgenie/common/constants.mjs @@ -0,0 +1,9 @@ +export default { + PRIORITY_OPTIONS: [ + "P1", + "P2", + "P3", + "P4", + "P5", + ], +}; diff --git a/components/opsgenie/opsgenie.app.mjs b/components/opsgenie/opsgenie.app.mjs new file mode 100644 index 0000000000000..3de6cf5940eff --- /dev/null +++ b/components/opsgenie/opsgenie.app.mjs @@ -0,0 +1,101 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "opsgenie", + propDefinitions: { + user: { + type: "string", + label: "User ID", + description: "ID of the User", + async options() { + const response = await this.listUsers(); + const usersIds = response.data; + return usersIds.map(({ + id, fullName, + }) => ({ + value: id, + label: fullName, + })); + }, + }, + message: { + type: "string", + label: "message", + description: "The message of the alert", + }, + note: { + type: "string", + label: "Note", + description: "Note of the alert", + }, + description: { + type: "string", + label: "Description", + description: "Description of the alert", + }, + tags: { + type: "string[]", + label: "Tags", + description: "Tags of the alert", + }, + priority: { + type: "string", + label: "Priority", + description: "Priority of the alert", + options: constants.PRIORITY_OPTIONS, + }, + requestId: { + type: "string", + label: "Request ID", + description: "ID of the alert request to be checked", + }, + }, + methods: { + _baseUrl() { + return `https://${this.$auth.instance_region}.opsgenie.com/v2`; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + APIKey, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `GenieKey ${APIKey}`, + }, + }); + }, + async createAlert(args = {}) { + return this._makeRequest({ + method: "post", + path: "/alerts", + APIKey: this.$auth.team_api_key, + ...args, + }); + }, + async getAlertStatus({ + requestId, ...args + }) { + return this._makeRequest({ + path: `/alerts/requests/${requestId}`, + APIKey: this.$auth.team_api_key, + ...args, + }); + }, + async listUsers(args = {}) { + return this._makeRequest({ + path: "/users", + APIKey: this.$auth.api_key, + ...args, + }); + }, + }, +}; diff --git a/components/opsgenie/package.json b/components/opsgenie/package.json index 823a199c4e7bb..f5cce02322051 100644 --- a/components/opsgenie/package.json +++ b/components/opsgenie/package.json @@ -1,16 +1,18 @@ { "name": "@pipedream/opsgenie", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Opsgenie Components", - "main": "dist/app/opsgenie.app.mjs", + "main": "opsgenie.app.mjs", "keywords": [ "pipedream", "opsgenie" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/opsgenie", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb009b623946e..33beff4da542a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6628,7 +6628,10 @@ importers: '@pipedream/platform': 0.9.0 components/opsgenie: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.1 + dependencies: + '@pipedream/platform': 3.0.1 components/optimoroute: specifiers: {} @@ -12686,55 +12689,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'} @@ -12970,7 +12924,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 @@ -13012,6 +12966,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'} @@ -17472,7 +17475,7 @@ 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