diff --git a/components/elorus/actions/create-task/create-task.mjs b/components/elorus/actions/create-task/create-task.mjs new file mode 100644 index 0000000000000..59d1fa45002db --- /dev/null +++ b/components/elorus/actions/create-task/create-task.mjs @@ -0,0 +1,56 @@ +import app from "../../elorus.app.mjs"; + +export default { + key: "elorus-create-task", + name: "Create Task", + description: "Create a new task in Elorus. [See the documentation](https://developer.elorus.com/#operation/tasks_create)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + hourlyRate: { + propDefinition: [ + app, + "hourlyRate", + ], + }, + project: { + propDefinition: [ + app, + "project", + ], + }, + active: { + propDefinition: [ + app, + "active", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createTask({ + $, + data: { + name: this.name, + description: this.description, + hourly_rate: this.hourlyRate, + project: this.project, + active: this.active, + }, + }); + $.export("$summary", "Successfully created the task with id: " + response.id); + return response; + }, +}; diff --git a/components/elorus/actions/delete-tasks/delete-tasks.mjs b/components/elorus/actions/delete-tasks/delete-tasks.mjs new file mode 100644 index 0000000000000..2de9a7a49ae93 --- /dev/null +++ b/components/elorus/actions/delete-tasks/delete-tasks.mjs @@ -0,0 +1,26 @@ +import app from "../../elorus.app.mjs"; + +export default { + key: "elorus-delete-tasks", + name: "Delete Tasks", + description: "Delete a task from Elorus. [See the documentation](https://developer.elorus.com/#operation/tasks_delete)", + version: "0.0.1", + type: "action", + props: { + app, + taskId: { + propDefinition: [ + app, + "taskId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.deleteTasks({ + $, + taskId: this.taskId, + }); + $.export("$summary", "Successfully deleted the task with ID: " + this.taskId); + return response; + }, +}; diff --git a/components/elorus/actions/get-tasks/get-tasks.mjs b/components/elorus/actions/get-tasks/get-tasks.mjs new file mode 100644 index 0000000000000..4addfa0caacd6 --- /dev/null +++ b/components/elorus/actions/get-tasks/get-tasks.mjs @@ -0,0 +1,44 @@ +import app from "../../elorus.app.mjs"; + +export default { + key: "elorus-get-tasks", + name: "Get Tasks", + description: "Get a list of tasks from Elorus. [See the documentation](https://developer.elorus.com/#operation/tasks_list)", + version: "0.0.1", + type: "action", + props: { + app, + search: { + propDefinition: [ + app, + "search", + ], + }, + project: { + propDefinition: [ + app, + "project", + ], + }, + active: { + propDefinition: [ + app, + "active", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getTasks({ + $, + params: { + search: this.search, + project: this.project, + active: this.active + ? 1 + : 0, + }, + }); + $.export("$summary", "Successfully sent the request and retrieved " + response.results.length + " results"); + return response; + }, +}; diff --git a/components/elorus/elorus.app.mjs b/components/elorus/elorus.app.mjs index 3713ce01c5bfb..6a764206597f7 100644 --- a/components/elorus/elorus.app.mjs +++ b/components/elorus/elorus.app.mjs @@ -1,11 +1,134 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "elorus", - propDefinitions: {}, + propDefinitions: { + name: { + type: "string", + label: "Name", + description: "The name of the task", + }, + description: { + type: "string", + label: "Description", + description: "Short description of the task", + optional: true, + }, + hourlyRate: { + type: "string", + label: "Hourly Rate", + description: "The hourly rate of the task", + optional: true, + }, + project: { + type: "string", + label: "Project", + description: "The project associated with the task", + async options() { + const response = await this.getProjects(); + const projectsIds = response.results; + return projectsIds.map(({ + id, + name, + }) => ({ + value: id, + label: name, + })); + }, + optional: true, + }, + active: { + type: "boolean", + label: "Active", + description: "Specifies if the task is active", + optional: true, + }, + taskId: { + type: "string", + label: "Task Id", + description: "The unique identifier of the task", + async options({ page }) { + try { + const response = await this.getTasks({ + params: { + "page": page + 1, + "page_size": 100, + }, + }); + const tasks = response.results || []; + if (!tasks.length) { + return []; + } + return tasks.map(({ + id, name, + }) => ({ + value: id, + label: name, + })); + } catch (err) { + if (err.response?.data?.detail === "Invalid page.") { + return []; + } + throw err; + } + }, + }, + search: { + type: "string", + label: "Search", + description: "A search term", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.elorus.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `Token ${this.$auth.api_key}`, + "X-Elorus-Organization": `${this.$auth.organization_id}`, + ...headers, + }, + }); + }, + async getTasks(args = {}) { + return this._makeRequest({ + path: "/v1.2/tasks/", + ...args, + }); + }, + async getProjects(args = {}) { + return this._makeRequest({ + path: "/v1.2/projects/", + ...args, + }); + }, + async deleteTasks({ + taskId, ...args + }) { + return this._makeRequest({ + path: `/v1.2/tasks/${taskId}/`, + method: "delete", + ...args, + }); + }, + async createTask(args = {}) { + return this._makeRequest({ + path: "/v1.2/tasks/", + method: "post", + ...args, + }); }, }, }; diff --git a/components/elorus/package.json b/components/elorus/package.json index 470bacd6ba693..8ccc883a4b985 100644 --- a/components/elorus/package.json +++ b/components/elorus/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/elorus", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Elorus Components", "main": "elorus.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "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 48fcea4d2c2ca..278f1412a9956 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4416,7 +4416,11 @@ importers: components/elopage: {} - components/elorus: {} + components/elorus: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/email: dependencies: @@ -15944,8 +15948,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/xano_metadata_api: - specifiers: {} + components/xano_metadata_api: {} components/xata: dependencies: @@ -38581,6 +38584,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: