From da5c98d93824b9edbb30cdc09ab09c2edf1a332c Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Tue, 10 Sep 2024 14:58:16 -0400 Subject: [PATCH] new components --- .../actions/create-client/create-client.mjs | 45 ++++++++ .../actions/create-project/create-project.mjs | 86 ++++++++++++++ .../get-current-time-entry.mjs | 2 +- .../get-time-entries/get-time-entries.mjs | 2 +- .../actions/get-time-entry/get-time-entry.mjs | 2 +- .../actions/update-client/update-client.mjs | 61 ++++++++++ .../actions/update-project/update-project.mjs | 101 ++++++++++++++++ components/toggl/package.json | 2 +- .../new-start-time-entry.mjs | 2 +- .../sources/new-time-entry/new-time-entry.mjs | 2 +- .../new-update-time-entry.mjs | 2 +- .../new-webhook-event/new-webhook-event.mjs | 2 +- components/toggl/toggl.app.mjs | 108 ++++++++++++++++++ 13 files changed, 409 insertions(+), 8 deletions(-) create mode 100644 components/toggl/actions/create-client/create-client.mjs create mode 100644 components/toggl/actions/create-project/create-project.mjs create mode 100644 components/toggl/actions/update-client/update-client.mjs create mode 100644 components/toggl/actions/update-project/update-project.mjs diff --git a/components/toggl/actions/create-client/create-client.mjs b/components/toggl/actions/create-client/create-client.mjs new file mode 100644 index 0000000000000..d6c76cfb3caac --- /dev/null +++ b/components/toggl/actions/create-client/create-client.mjs @@ -0,0 +1,45 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + key: "toggl-create-client", + name: "Create Client", + description: "Create a new client in Toggl. [See the documentation](https://engineering.toggl.com/docs/api/clients#post-create-client)", + version: "0.0.1", + type: "action", + props: { + toggl, + workspaceId: { + propDefinition: [ + toggl, + "workspaceId", + ], + }, + name: { + propDefinition: [ + toggl, + "clientName", + ], + }, + notes: { + propDefinition: [ + toggl, + "notes", + ], + }, + }, + async run({ $ }) { + const response = await this.toggl.createClient({ + $, + workspaceId: this.workspaceId, + data: { + name: this.name, + notes: this.notes, + wid: this.workspaceId, + }, + }); + if (response.id) { + $.export("$summary", `Successfully created client with ID: ${response.id}`); + } + return response; + }, +}; diff --git a/components/toggl/actions/create-project/create-project.mjs b/components/toggl/actions/create-project/create-project.mjs new file mode 100644 index 0000000000000..e5572300820be --- /dev/null +++ b/components/toggl/actions/create-project/create-project.mjs @@ -0,0 +1,86 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + key: "toggl-create-project", + name: "Create Project", + description: "Create a new project in Toggl. [See the documentation](https://engineering.toggl.com/docs/api/projects#post-workspaceprojects)", + version: "0.0.1", + type: "action", + props: { + toggl, + workspaceId: { + propDefinition: [ + toggl, + "workspaceId", + ], + }, + name: { + propDefinition: [ + toggl, + "projectName", + ], + }, + startDate: { + propDefinition: [ + toggl, + "startDate", + ], + }, + endDate: { + propDefinition: [ + toggl, + "endDate", + ], + }, + active: { + type: "boolean", + label: "Active", + description: "Whether the project is active or archived. Defaults to `true`.", + optional: true, + default: true, + }, + isPrivate: { + type: "boolean", + label: "Is Private?", + description: "Whether the project is private or not. Defaults to `false`.", + optional: true, + default: false, + }, + isShared: { + type: "boolean", + label: "Is Shared?", + description: "Whether the project is shared or not. Defaults to `false`.", + optional: true, + default: false, + }, + clientId: { + propDefinition: [ + toggl, + "clientId", + (c) => ({ + workspaceId: c.workspaceId, + }), + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.toggl.createProject({ + $, + workspaceId: this.workspaceId, + data: { + name: this.name, + start_date: this.startDate, + end_date: this.endDate, + active: this.active, + is_private: this.isPrivate, + is_shared: this.isShared, + client_id: this.clientId, + }, + }); + if (response.id) { + $.export("$summary", `Successfully created project with ID: ${response.id}`); + } + return response; + }, +}; diff --git a/components/toggl/actions/get-current-time-entry/get-current-time-entry.mjs b/components/toggl/actions/get-current-time-entry/get-current-time-entry.mjs index 8d73dd1327e02..a7ba3b99d6979 100644 --- a/components/toggl/actions/get-current-time-entry/get-current-time-entry.mjs +++ b/components/toggl/actions/get-current-time-entry/get-current-time-entry.mjs @@ -2,7 +2,7 @@ import toggl from "../../toggl.app.mjs"; export default { name: "Get Current Time Entry", - version: "0.0.5", + version: "0.0.6", key: "toggl-get-current-time-entry", description: "Get the time entry that is running now. [See docs here]https://developers.track.toggl.com/docs/api/time_entries#get-get-current-time-entry)", type: "action", diff --git a/components/toggl/actions/get-time-entries/get-time-entries.mjs b/components/toggl/actions/get-time-entries/get-time-entries.mjs index 23f08e3fb8083..527e02a0426a6 100644 --- a/components/toggl/actions/get-time-entries/get-time-entries.mjs +++ b/components/toggl/actions/get-time-entries/get-time-entries.mjs @@ -2,7 +2,7 @@ import toggl from "../../toggl.app.mjs"; export default { name: "Get Time Entries", - version: "0.0.5", + version: "0.0.6", key: "toggl-get-time-entries", description: "Get the last thousand time entries. [See docs here](https://developers.track.toggl.com/docs/api/time_entries#get-timeentries)", type: "action", diff --git a/components/toggl/actions/get-time-entry/get-time-entry.mjs b/components/toggl/actions/get-time-entry/get-time-entry.mjs index 3c6b7e66f1f91..8878141ebff4a 100644 --- a/components/toggl/actions/get-time-entry/get-time-entry.mjs +++ b/components/toggl/actions/get-time-entry/get-time-entry.mjs @@ -2,7 +2,7 @@ import toggl from "../../toggl.app.mjs"; export default { name: "Get Time Entry", - version: "0.0.5", + version: "0.0.6", key: "toggl-get-time-entry", description: "Get details about a specific time entry. [See docs here](https://developers.track.toggl.com/docs/api/time_entries)", type: "action", diff --git a/components/toggl/actions/update-client/update-client.mjs b/components/toggl/actions/update-client/update-client.mjs new file mode 100644 index 0000000000000..cd7cd446f9e86 --- /dev/null +++ b/components/toggl/actions/update-client/update-client.mjs @@ -0,0 +1,61 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + key: "toggl-update-client", + name: "Update Client", + description: "Updates an existing client in Toggl. [See the documentation](https://engineering.toggl.com/docs/api/clients#put-change-client)", + version: "0.0.1", + type: "action", + props: { + toggl, + workspaceId: { + propDefinition: [ + toggl, + "workspaceId", + ], + }, + clientId: { + propDefinition: [ + toggl, + "clientId", + (c) => ({ + workspaceId: c.workspaceId, + }), + ], + }, + name: { + propDefinition: [ + toggl, + "clientName", + ], + optional: true, + }, + notes: { + propDefinition: [ + toggl, + "notes", + ], + }, + }, + async run({ $ }) { + const client = await this.toggl.getClient({ + $, + workspaceId: this.workspaceId, + clientId: this.clientId, + }); + const response = await this.toggl.updateClient({ + $, + workspaceId: this.workspaceId, + clientId: this.clientId, + data: { + name: this.name || client.name, + notes: this.notes || client.notes, + wid: this.workspaceId, + }, + }); + if (response.id) { + $.export("$summary", `Successfully updated client with ID: ${response.id}`); + } + return response; + }, +}; diff --git a/components/toggl/actions/update-project/update-project.mjs b/components/toggl/actions/update-project/update-project.mjs new file mode 100644 index 0000000000000..475aca3c66885 --- /dev/null +++ b/components/toggl/actions/update-project/update-project.mjs @@ -0,0 +1,101 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + key: "toggl-update-project", + name: "Update Project", + description: "Updates an existing project in Toggl. [See the documentation](https://engineering.toggl.com/docs/api/projects#put-workspaceproject)", + version: "0.0.1", + type: "action", + props: { + toggl, + workspaceId: { + propDefinition: [ + toggl, + "workspaceId", + ], + }, + projectId: { + propDefinition: [ + toggl, + "projectId", + (c) => ({ + workspaceId: c.workspaceId, + }), + ], + }, + name: { + propDefinition: [ + toggl, + "projectName", + ], + optional: true, + }, + startDate: { + propDefinition: [ + toggl, + "startDate", + ], + optional: true, + }, + endDate: { + propDefinition: [ + toggl, + "endDate", + ], + optional: true, + }, + active: { + type: "boolean", + label: "Active", + description: "Whether the project is active or archived.", + optional: true, + }, + isPrivate: { + type: "boolean", + label: "Is Private?", + description: "Whether the project is private or not.", + optional: true, + }, + isShared: { + type: "boolean", + label: "Is Shared?", + description: "Whether the project is shared or not.", + optional: true, + }, + clientId: { + propDefinition: [ + toggl, + "clientId", + (c) => ({ + workspaceId: c.workspaceId, + }), + ], + optional: true, + }, + }, + async run({ $ }) { + const project = await this.toggl.getProject({ + $, + workspaceId: this.workspaceId, + projectId: this.projectId, + }); + const response = await this.toggl.updateProject({ + $, + workspaceId: this.workspaceId, + projectId: this.projectId, + data: { + name: this.name || project.name, + start_date: this.startDate || project.start_date, + end_date: this.endDate || project.end_date, + active: this.active || project.active, + is_private: this.isPrivate || project.isPrivate, + is_shared: this.isShared || project.is_shared, + client_id: this.clientId || project.client_id, + }, + }); + if (response.id) { + $.export("$summary", `Successfully updated project with ID: ${response.id}`); + } + return response; + }, +}; diff --git a/components/toggl/package.json b/components/toggl/package.json index c47df6d0f3421..b4ed8cc78bdc8 100644 --- a/components/toggl/package.json +++ b/components/toggl/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/toggl", - "version": "0.0.6", + "version": "0.1.0", "description": "Pipedream Toggl Components", "main": "toggl.app.js", "keywords": [ diff --git a/components/toggl/sources/new-start-time-entry/new-start-time-entry.mjs b/components/toggl/sources/new-start-time-entry/new-start-time-entry.mjs index cdca4d7f8224d..f165384cf166c 100644 --- a/components/toggl/sources/new-start-time-entry/new-start-time-entry.mjs +++ b/components/toggl/sources/new-start-time-entry/new-start-time-entry.mjs @@ -3,7 +3,7 @@ import base from "../common/base.mjs"; export default { ...base, name: "New Start Time Entry (Instant)", - version: "0.0.3", + version: "0.0.4", key: "toggl-new-start-time-entry", description: "Emit new event when a time entry is started. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)", type: "source", diff --git a/components/toggl/sources/new-time-entry/new-time-entry.mjs b/components/toggl/sources/new-time-entry/new-time-entry.mjs index 2397ce0a1599b..f331e59cb712b 100644 --- a/components/toggl/sources/new-time-entry/new-time-entry.mjs +++ b/components/toggl/sources/new-time-entry/new-time-entry.mjs @@ -3,7 +3,7 @@ import base from "../common/base.mjs"; export default { ...base, name: "New Time Entry (Instant)", - version: "0.0.3", + version: "0.0.4", key: "toggl-new-time-entry", description: "Emit new event when a time entry is created. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)", type: "source", diff --git a/components/toggl/sources/new-update-time-entry/new-update-time-entry.mjs b/components/toggl/sources/new-update-time-entry/new-update-time-entry.mjs index 64635545f51e1..2ecab32fe3250 100644 --- a/components/toggl/sources/new-update-time-entry/new-update-time-entry.mjs +++ b/components/toggl/sources/new-update-time-entry/new-update-time-entry.mjs @@ -3,7 +3,7 @@ import base from "../common/base.mjs"; export default { ...base, name: "New Update Time Entry (Instant)", - version: "0.0.3", + version: "0.0.4", key: "toggl-new-update-time-entry", description: "Emit new event when a time entry is updated. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)", type: "source", diff --git a/components/toggl/sources/new-webhook-event/new-webhook-event.mjs b/components/toggl/sources/new-webhook-event/new-webhook-event.mjs index 0a4c8df83019a..ab086ad3e2fc4 100644 --- a/components/toggl/sources/new-webhook-event/new-webhook-event.mjs +++ b/components/toggl/sources/new-webhook-event/new-webhook-event.mjs @@ -4,7 +4,7 @@ import constants from "../common/constants.mjs"; export default { ...base, name: "New Webhook Event (Instant)", - version: "0.0.3", + version: "0.0.4", key: "toggl-new-webhook-event", description: "Emit new event on receive a webhook event. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)", type: "source", diff --git a/components/toggl/toggl.app.mjs b/components/toggl/toggl.app.mjs index fa2dca390c64c..1becfff3707d3 100644 --- a/components/toggl/toggl.app.mjs +++ b/components/toggl/toggl.app.mjs @@ -39,6 +39,62 @@ export default { })); }, }, + clientId: { + label: "Client ID", + description: "The client ID", + type: "integer", + async options({ workspaceId }) { + const clients = await this.getClients({ + workspaceId, + }); + + return clients?.map((client) => ({ + label: client.name, + value: client.id, + })) || []; + }, + }, + projectId: { + label: "Project ID", + description: "The project ID", + type: "integer", + async options({ workspaceId }) { + const projects = await this.getProjects({ + workspaceId, + }); + + return projects?.map((project) => ({ + label: project.name, + value: project.id, + })) || []; + }, + }, + clientName: { + type: "string", + label: "Name", + description: "Name of the client", + }, + notes: { + type: "string", + label: "Notes", + description: "Notes about the client", + optional: true, + }, + projectName: { + type: "string", + label: "Name", + description: "Name of the project", + }, + startDate: { + type: "string", + label: "Start Date", + description: "The start date of the project in `YYYY-MM-DD` format", + }, + endDate: { + type: "string", + label: "End Date", + description: "The end date of the project in `YYYY-MM-DD` format", + }, }, methods: { _apiToken() { @@ -79,6 +135,16 @@ export default { getWorkspaces({ $ }) { return this._makeRequest("v9", "me/workspaces", {}, $); }, + getClients({ + workspaceId, $, + }) { + return this._makeRequest("v9", `workspaces/${workspaceId}/clients`, {}, $); + }, + getProjects({ + workspaceId, $, + }) { + return this._makeRequest("v9", `workspaces/${workspaceId}/projects`, {}, $); + }, getCurrentTimeEntry({ $ } = {}) { return this._makeRequest("v9", "me/time_entries/current", {}, $); }, @@ -97,5 +163,47 @@ export default { } = {}) { return this._makeRequest("v9", `me/time_entries/${timeEntryId}`, {}, $); }, + getClient({ + workspaceId, clientId, $, + } = {}) { + return this._makeRequest("v9", `workspaces/${workspaceId}/clients/${clientId}`, {}, $); + }, + getProject({ + workspaceId, projectId, $, + } = {}) { + return this._makeRequest("v9", `workspaces/${workspaceId}/projects/${projectId}`, {}, $); + }, + createClient({ + workspaceId, data, $, + }) { + return this._makeRequest("v9", `workspaces/${workspaceId}/clients`, { + method: "post", + data, + }, $); + }, + createProject({ + workspaceId, data, $, + }) { + return this._makeRequest("v9", `workspaces/${workspaceId}/projects`, { + method: "post", + data, + }, $); + }, + updateClient({ + workspaceId, clientId, data, $, + }) { + return this._makeRequest("v9", `workspaces/${workspaceId}/clients/${clientId}`, { + method: "put", + data, + }, $); + }, + updateProject({ + workspaceId, projectId, data, $, + }) { + return this._makeRequest("v9", `workspaces/${workspaceId}/projects/${projectId}`, { + method: "put", + data, + }, $); + }, }, };