diff --git a/components/habitica/.gitignore b/components/habitica/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/habitica/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/habitica/actions/create-challenge/create-challenge.mjs b/components/habitica/actions/create-challenge/create-challenge.mjs new file mode 100644 index 0000000000000..6b0c48e8cea0a --- /dev/null +++ b/components/habitica/actions/create-challenge/create-challenge.mjs @@ -0,0 +1,79 @@ +import app from "../../habitica.app.mjs"; + +export default { + key: "habitica-create-challenge", + name: "Create Challenge", + description: "Creates a challenge. [See the documentation](https://habitica.com/apidoc/#api-Challenge-CreateChallenge)", + version: "0.0.1", + type: "action", + props: { + app, + type: { + propDefinition: [ + app, + "type", + ], + }, + group: { + propDefinition: [ + app, + "group", + (c) => ({ + type: c.type, + }), + ], + }, + name: { + propDefinition: [ + app, + "name", + ], + }, + shortName: { + propDefinition: [ + app, + "shortName", + ], + }, + summary: { + propDefinition: [ + app, + "summary", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + official: { + propDefinition: [ + app, + "official", + ], + }, + prize: { + propDefinition: [ + app, + "prize", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createChallenge({ + $, + data: { + group: this.group, + name: this.name, + shortName: this.shortName, + summary: this.summary, + description: this.description, + official: this.official, + prize: this.prize, + }, + }); + $.export("$summary", "Successfully created challenge with ID: " + response.data._id); + return response; + }, +}; diff --git a/components/habitica/actions/delete-challenge/delete-challenge.mjs b/components/habitica/actions/delete-challenge/delete-challenge.mjs new file mode 100644 index 0000000000000..8485bfe80cbf8 --- /dev/null +++ b/components/habitica/actions/delete-challenge/delete-challenge.mjs @@ -0,0 +1,26 @@ +import app from "../../habitica.app.mjs"; + +export default { + key: "habitica-delete-challenge", + name: "Delete Challenge", + description: "Delete the challenge with the specified ID. [See the documentation](https://habitica.com/apidoc/#api-Challenge-DeleteChallenge)", + version: "0.0.1", + type: "action", + props: { + app, + challengeId: { + propDefinition: [ + app, + "challengeId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.deleteChallenge({ + $, + challengeId: this.challengeId, + }); + $.export("$summary", "Successfully deleted the challenge with ID: " + this.challengeId); + return response; + }, +}; diff --git a/components/habitica/actions/get-challenge/get-challenge.mjs b/components/habitica/actions/get-challenge/get-challenge.mjs new file mode 100644 index 0000000000000..8f87de5eb1452 --- /dev/null +++ b/components/habitica/actions/get-challenge/get-challenge.mjs @@ -0,0 +1,26 @@ +import app from "../../habitica.app.mjs"; + +export default { + key: "habitica-get-challenge", + name: "Get Challenge", + description: "Get data for the challenge with the specified ID. [See the documentation](https://habitica.com/apidoc/#api-Challenge-GetChallenge)", + version: "0.0.1", + type: "action", + props: { + app, + challengeId: { + propDefinition: [ + app, + "challengeId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getChallenge({ + $, + challengeId: this.challengeId, + }); + $.export("$summary", "Successfully retrieved the challenge with ID: " + this.challengeId); + return response; + }, +}; diff --git a/components/habitica/app/habitica.app.ts b/components/habitica/app/habitica.app.ts deleted file mode 100644 index 9b573aa85e180..0000000000000 --- a/components/habitica/app/habitica.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "habitica", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); diff --git a/components/habitica/common/constants.mjs b/components/habitica/common/constants.mjs new file mode 100644 index 0000000000000..27df0293e7fcb --- /dev/null +++ b/components/habitica/common/constants.mjs @@ -0,0 +1,9 @@ +export default { + GROUP_TYPES: [ + "party", + "guilds", + "privateGuilds", + "publicGuilds", + "tavern", + ], +}; diff --git a/components/habitica/habitica.app.mjs b/components/habitica/habitica.app.mjs new file mode 100644 index 0000000000000..34fd0f8bbd790 --- /dev/null +++ b/components/habitica/habitica.app.mjs @@ -0,0 +1,149 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "habitica", + propDefinitions: { + group: { + type: "string", + label: "Group", + description: "ID of the group to which the challenge belongs", + async options({ type }) { + const response = await this.getGroups({ + type, + }); + const groups = response.data; + return groups.map(({ + name, _id, + }) => ({ + label: name, + value: _id, + })); + }, + }, + name: { + type: "string", + label: "Name", + description: "Full name of the challenge", + }, + shortName: { + type: "string", + label: "Short Name", + description: "A shortened name for the challenge, to be used as a tag", + }, + summary: { + type: "string", + label: "Summary", + description: "A short summary advertising the main purpose of the challenge", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "A detailed description of the challenge", + optional: true, + }, + official: { + type: "boolean", + label: "Official", + description: "Whether or not a challenge is an official Habitica challenge", + optional: true, + }, + prize: { + type: "string", + label: "Prize", + description: "Number of gems offered as a prize to challenge winner", + optional: true, + }, + type: { + type: "string", + label: "Type", + description: "Type of the group", + options: constants.GROUP_TYPES, + }, + challengeId: { + type: "string", + label: "Challenge ID", + description: "ID of the challenge to update", + async options({ page }) { + const response = await this.getChallenges({ + params: { + page: page, + }, + }); + const challenges = response.data; + return challenges.map(({ + name, _id, + }) => ({ + label: name, + value: _id, + })); + }, + }, + }, + methods: { + _baseUrl() { + return "https://habitica.com/api/v3"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "x-client": "3a326108-1895-4c23-874e-37668c75f2ad-Pipedream", + "x-api-user": `${this.$auth.user_id}`, + "x-api-key": `${this.$auth.api_token}`, + }, + }); + }, + async createChallenge(args = {}) { + return this._makeRequest({ + path: "/challenges", + method: "post", + ...args, + }); + }, + async deleteChallenge({ + challengeId, ...args + }) { + return this._makeRequest({ + path: `/challenges/${challengeId}`, + method: "delete", + ...args, + }); + }, + async getChallenge({ + challengeId, ...args + }) { + return this._makeRequest({ + path: `/challenges/${challengeId}`, + ...args, + }); + }, + async getGroups({ + type, ...args + }) { + return this._makeRequest({ + path: "/groups", + params: { + type: type, + }, + ...args, + }); + }, + async getChallenges(args = {}) { + return this._makeRequest({ + path: "/challenges/user", + ...args, + }); + }, + }, +}; diff --git a/components/habitica/package.json b/components/habitica/package.json index 9d638b98d71e4..bb5c7e08f2627 100644 --- a/components/habitica/package.json +++ b/components/habitica/package.json @@ -1,16 +1,18 @@ { "name": "@pipedream/habitica", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Habitica Components", - "main": "dist/app/habitica.app.mjs", + "main": "habitica.app.mjs", "keywords": [ "pipedream", "habitica" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/habitica", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81a357245fbf5..b342802f453d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5892,7 +5892,11 @@ importers: specifier: ^2.29.4 version: 2.30.1 - components/habitica: {} + components/habitica: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/habitify: dependencies: @@ -18733,6 +18737,9 @@ packages: '@pipedream/platform@3.0.3': resolution: {integrity: sha512-7elalas41lnT8i6EAFkqB7fT/+hkLGEQ1njS6A7CVguTrEswaIYk/seKmkfkRY7+O6qncgnXswYIKCBML9Co7w==} + '@pipedream/platform@3.1.0': + resolution: {integrity: sha512-ELmV3fpd9PIUm74/RPaqmA7hJaY4ryIn6PCNT1NP/gnqMrkRNOAr+DTV4xPaJgPiRm74WC5HvrkC8YdRveXzZA==} + '@pipedream/postgresql@2.2.3': resolution: {integrity: sha512-Co9r4UKvvimEPo9T4v+EfVn/Sqqw8+X7PtvsAF7tydq7CHpkmOT9eYAiD0Kuybg5WbuWuqDaXHHmhVtsAxgpBw==} @@ -35456,7 +35463,7 @@ snapshots: '@pipedream/linear_app@0.7.1': dependencies: '@linear/sdk': 13.0.0 - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 transitivePeerDependencies: - debug - encoding @@ -35471,7 +35478,7 @@ snapshots: '@pipedream/monday@0.7.0': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 form-data: 4.0.2 lodash.flatmap: 4.5.0 lodash.map: 4.6.0 @@ -35484,7 +35491,7 @@ snapshots: '@pipedream/notion@0.6.2': dependencies: '@notionhq/client': 2.3.0 - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 '@tryfabric/martian': 1.2.4 lodash-es: 4.17.21 notion-to-md: 3.1.8 @@ -35590,6 +35597,17 @@ snapshots: transitivePeerDependencies: - debug + '@pipedream/platform@3.1.0': + dependencies: + axios: 1.9.0 + fp-ts: 2.16.10 + io-ts: 2.2.22(fp-ts@2.16.10) + mime-types: 3.0.1 + querystring: 0.2.1 + uuid: 11.1.0 + transitivePeerDependencies: + - debug + '@pipedream/postgresql@2.2.3': dependencies: '@pipedream/platform': 2.0.0 @@ -35601,13 +35619,13 @@ snapshots: '@pipedream/quickbooks@0.5.1': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 transitivePeerDependencies: - debug '@pipedream/ramp@0.1.2': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 uuid: 10.0.0 transitivePeerDependencies: - debug @@ -35644,14 +35662,14 @@ snapshots: '@pipedream/sftp@0.4.1': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 ssh2-sftp-client: 11.0.0 transitivePeerDependencies: - debug '@pipedream/shopify@0.7.0': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 async-retry: 1.3.3 bottleneck: 2.19.5 form-data: 4.0.2