From 4b31030882c7aac1f6a5c7ba05027dd7e38cd4b0 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 19 Mar 2025 09:21:36 -0300 Subject: [PATCH] Added actions --- .../actions/issue-badge/issue-badge.mjs | 90 +++++++++++++++++++ components/navigatr/navigatr.app.mjs | 89 ++++++++++++++++-- components/navigatr/package.json | 5 +- pnpm-lock.yaml | 14 +-- 4 files changed, 187 insertions(+), 11 deletions(-) create mode 100644 components/navigatr/actions/issue-badge/issue-badge.mjs diff --git a/components/navigatr/actions/issue-badge/issue-badge.mjs b/components/navigatr/actions/issue-badge/issue-badge.mjs new file mode 100644 index 0000000000000..4a04fbe79a9fb --- /dev/null +++ b/components/navigatr/actions/issue-badge/issue-badge.mjs @@ -0,0 +1,90 @@ +import app from "../../navigatr.app.mjs"; + +export default { + key: "navigatr-issue-badge", + name: "Issue Badge", + description: "Issue a badge to a recipient. [See the documentation](https://api.navigatr.app/docs#/Badge/issue_badge_v1_badge__badge_id__issue_put)", + version: "0.0.1", + type: "action", + props: { + app, + providerId: { + propDefinition: [ + app, + "providerId", + ], + }, + badgeId: { + propDefinition: [ + app, + "badgeId", + ], + }, + recipientHasAccount: { + propDefinition: [ + app, + "recipientHasAccount", + ], + reloadProps: true, + }, + recipientId: { + propDefinition: [ + app, + "recipientId", + ], + }, + recipientEmail: { + propDefinition: [ + app, + "recipientEmail", + ], + disabled: true, + hidden: true, + }, + recipientFirstname: { + propDefinition: [ + app, + "recipientFirstname", + ], + disabled: true, + hidden: true, + }, + recipientLastname: { + propDefinition: [ + app, + "recipientLastname", + ], + disabled: true, + hidden: true, + }, + }, + async additionalProps(existingProps) { + const props = {}; + if (!this.recipientHasAccount) { + existingProps.recipientId.hidden = true; + existingProps.recipientId.disabled = true; + existingProps.recipientEmail.hidden = false; + existingProps.recipientEmail.disabled = false; + existingProps.recipientFirstname.hidden = false; + existingProps.recipientFirstname.disabled = false; + existingProps.recipientLastname.hidden = false; + existingProps.recipientLastname.disabled = false; + } + return props; + }, + async run({ $ }) { + const response = await this.app.issueBadge({ + $, + badgeId: this.badgeId, + data: { + provider_id: this.providerId, + recipient_id: this.recipientId, + recipient_email: this.recipientEmail, + recipient_firstname: this.recipientFirstname, + recipient_lastname: this.recipientLastname, + }, + }); + $.export("$summary", "Successfully issued badge"); + return response; + }, +}; diff --git a/components/navigatr/navigatr.app.mjs b/components/navigatr/navigatr.app.mjs index ed8cb8e9e2815..3629d5501c188 100644 --- a/components/navigatr/navigatr.app.mjs +++ b/components/navigatr/navigatr.app.mjs @@ -1,11 +1,90 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "navigatr", - propDefinitions: {}, + propDefinitions: { + providerId: { + type: "string", + label: "Provider ID", + description: "ID of the badge provider", + async options() { + const response = await this.getUserDetails(); + const providerIds = response.providers; + return providerIds.map(({ + name, id, + }) => ({ + label: name, + value: id, + })); + }, + }, + recipientHasAccount: { + type: "boolean", + label: "Recipient Has Account", + description: "Does the recipient have an account in the system?", + }, + recipientId: { + type: "string", + label: "Recipient ID", + description: "ID of the badge recipient", + }, + recipientEmail: { + type: "string", + label: "Recipient Email", + description: "Email of the recipient", + }, + recipientFirstname: { + type: "string", + label: "First Name", + description: "First Name of the recipient", + }, + recipientLastname: { + type: "string", + label: "Last Name", + description: "Last Name of the recipient", + }, + badgeId: { + type: "string", + label: "Badge ID", + description: "ID of the badge to be issued", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.navigatr.app/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + ...headers, + }, + }); + }, + + async issueBadge({ + badgeId, ...args + }) { + return this._makeRequest({ + path: `/badge/${badgeId}/issue`, + method: "put", + ...args, + }); + }, + async getUserDetails(args = {}) { + return this._makeRequest({ + path: "/user_detail/0", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/navigatr/package.json b/components/navigatr/package.json index 531e4bc412fd6..79abe62c43d5b 100644 --- a/components/navigatr/package.json +++ b/components/navigatr/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/navigatr", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Navigatr Components", "main": "navigatr.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "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 e4c11cb38fdd9..b17104dee1272 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -421,8 +421,7 @@ importers: components/agentos: {} - components/agentql: - specifiers: {} + components/agentql: {} components/agenty: dependencies: @@ -4050,8 +4049,7 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/enginemailer: - specifiers: {} + components/enginemailer: {} components/enigma: {} @@ -8289,7 +8287,11 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/navigatr: {} + components/navigatr: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/ncscale: dependencies: @@ -34318,6 +34320,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: