diff --git a/components/tmetric/actions/create-time-entry/create-time-entry.mjs b/components/tmetric/actions/create-time-entry/create-time-entry.mjs new file mode 100644 index 0000000000000..10dee091534c8 --- /dev/null +++ b/components/tmetric/actions/create-time-entry/create-time-entry.mjs @@ -0,0 +1,68 @@ +import app from "../../tmetric.app.mjs"; + +export default { + key: "tmetric-create-time-entry", + name: "Create Time Entry", + description: "Create a new Time Entry. [See the documentation](https://app.tmetric.com/api-docs/?_gl=1*n76hcy*_gcl_aw*R0NMLjE3NjQwOTU2MDguQ2owS0NRaUF4SlhKQmhEX0FSSXNBSF9KR2pncU8zZzgxcHp3VUhQWGdjazEyUWFTaThXeE00ZTBUZ1hvak5ma1AzeG10a1pGYWJuek8wOGFBbC1KRUFMd193Y0I.*_gcl_au*MjU2MzU4NTI3LjE3NjQwOTU2MDg.*_ga*ODE4ODUyMDE2LjE3NjQwOTU2MDM.*_ga_66EFKVJKC5*czE3NjQwOTU2MDMkbzEkZzEkdDE3NjQwOTYyODkkajQzJGwwJGgw#/Time%20Entries/post-accounts-accountId-timeentries)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + app, + accountId: { + propDefinition: [ + app, + "accountId", + ], + }, + startTime: { + propDefinition: [ + app, + "startTime", + ], + }, + endTime: { + propDefinition: [ + app, + "endTime", + ], + }, + note: { + propDefinition: [ + app, + "note", + ], + }, + isBillable: { + propDefinition: [ + app, + "isBillable", + ], + }, + isInvoiced: { + propDefinition: [ + app, + "isInvoiced", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createTimeEntry({ + $, + accountId: this.accountId, + data: { + startTime: this.startTime ?? "", + endTime: this.endTime ?? "", + note: this.note, + isBillable: this.isBillable, + isInvoiced: this.isInvoiced, + }, + }); + $.export("$summary", "Successfully created time entry with ID: " + response[0].id); + return response; + }, +}; diff --git a/components/tmetric/actions/delete-time-entry/delete-time-entry.mjs b/components/tmetric/actions/delete-time-entry/delete-time-entry.mjs new file mode 100644 index 0000000000000..740c8fb6dc455 --- /dev/null +++ b/components/tmetric/actions/delete-time-entry/delete-time-entry.mjs @@ -0,0 +1,43 @@ +import app from "../../tmetric.app.mjs"; + +export default { + key: "tmetric-delete-time-entry", + name: "Delete Time Entry", + description: "Delete the specified Time Entry. [See the documentation](https://app.tmetric.com/api-docs/?_gl=1*n76hcy*_gcl_aw*R0NMLjE3NjQwOTU2MDguQ2owS0NRaUF4SlhKQmhEX0FSSXNBSF9KR2pncU8zZzgxcHp3VUhQWGdjazEyUWFTaThXeE00ZTBUZ1hvak5ma1AzeG10a1pGYWJuek8wOGFBbC1KRUFMd193Y0I.*_gcl_au*MjU2MzU4NTI3LjE3NjQwOTU2MDg.*_ga*ODE4ODUyMDE2LjE3NjQwOTU2MDM.*_ga_66EFKVJKC5*czE3NjQwOTU2MDMkbzEkZzEkdDE3NjQwOTYyODkkajQzJGwwJGgw#/Time%20Entries/delete-accounts-accountId-timeentries-timeEntryId)", + version: "0.0.1", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + app, + accountId: { + propDefinition: [ + app, + "accountId", + ], + }, + timeEntryId: { + propDefinition: [ + app, + "timeEntryId", + (c) => ({ + accountId: c.accountId, + }), + ], + }, + }, + async run({ $ }) { + const response = await this.app.deleteTimeEntry({ + $, + data: { + accountId: this.accountId, + timeEntryId: this.timeEntryId, + }, + }); + $.export("$summary", "Successfully deleted time entry with ID: " + this.timeEntryId); + return response; + }, +}; diff --git a/components/tmetric/actions/modify-time-entry/modify-time-entry.mjs b/components/tmetric/actions/modify-time-entry/modify-time-entry.mjs new file mode 100644 index 0000000000000..4558b38f56d4e --- /dev/null +++ b/components/tmetric/actions/modify-time-entry/modify-time-entry.mjs @@ -0,0 +1,78 @@ +import app from "../../tmetric.app.mjs"; + +export default { + key: "tmetric-modify-time-entry", + name: "Modify Time Entry", + description: "Modify the specified Time Entry. [See the documentation](https://app.tmetric.com/api-docs/?_gl=1*n76hcy*_gcl_aw*R0NMLjE3NjQwOTU2MDguQ2owS0NRaUF4SlhKQmhEX0FSSXNBSF9KR2pncU8zZzgxcHp3VUhQWGdjazEyUWFTaThXeE00ZTBUZ1hvak5ma1AzeG10a1pGYWJuek8wOGFBbC1KRUFMd193Y0I.*_gcl_au*MjU2MzU4NTI3LjE3NjQwOTU2MDg.*_ga*ODE4ODUyMDE2LjE3NjQwOTU2MDM.*_ga_66EFKVJKC5*czE3NjQwOTU2MDMkbzEkZzEkdDE3NjQwOTYyODkkajQzJGwwJGgw#/Time%20Entries/put-accounts-accountId-timeentries-timeEntryId)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + app, + accountId: { + propDefinition: [ + app, + "accountId", + ], + }, + timeEntryId: { + propDefinition: [ + app, + "timeEntryId", + (c) => ({ + accountId: c.accountId, + }), + ], + }, + startTime: { + propDefinition: [ + app, + "startTime", + ], + }, + endTime: { + propDefinition: [ + app, + "endTime", + ], + }, + note: { + propDefinition: [ + app, + "note", + ], + }, + isBillable: { + propDefinition: [ + app, + "isBillable", + ], + }, + isInvoiced: { + propDefinition: [ + app, + "isInvoiced", + ], + }, + }, + async run({ $ }) { + const response = await this.app.modifyTimeEntry({ + $, + accountId: this.accountId, + timeEntryId: this.timeEntryId, + data: { + startTime: this.startTime ?? "", + endTime: this.endTime ?? "", + note: this.note, + isBillable: this.isBillable, + isInvoiced: this.isInvoiced, + }, + }); + $.export("$summary", "Successfully modified the time entry with ID: " + this.timeEntryId); + return response; + }, +}; diff --git a/components/tmetric/package.json b/components/tmetric/package.json index 1b046f0a28393..346eb387136e6 100644 --- a/components/tmetric/package.json +++ b/components/tmetric/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/tmetric", - "version": "0.0.6", + "version": "0.1.0", "description": "Pipedream TMetric Components", "main": "tmetric.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/components/tmetric/tmetric.app.mjs b/components/tmetric/tmetric.app.mjs index 36e4bc6d266f4..822c2f81b5af7 100644 --- a/components/tmetric/tmetric.app.mjs +++ b/components/tmetric/tmetric.app.mjs @@ -1,11 +1,132 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "tmetric", - propDefinitions: {}, + propDefinitions: { + accountId: { + type: "string", + label: "Account ID", + description: "Identifier of the account", + async options() { + const response = await this.getUser(); + const accounts = response.accounts; + return accounts.map(({ + id, name, + }) => ({ + value: id, + label: name, + })); + }, + }, + timeEntryId: { + type: "string", + label: "Time Entry ID", + description: "Identifier of the time entry", + async options({ accountId }) { + const response = await this.getTimeEntries({ + accountId, + }); + return response.map(({ + id, note, + }) => ({ + value: id, + label: note, + })); + }, + }, + startTime: { + type: "string", + label: "Start Time", + description: "Start timestamp in ISO format, e.g. `2025-11-26T14:16:00`; leave null to start the timer at the current moment", + optional: true, + }, + endTime: { + type: "string", + label: "End Time", + description: "End timestamp in ISO format, e.g. `2025-11-26T15:16:00`; leave null to keep the timer running indefinitely", + optional: true, + }, + note: { + type: "string", + label: "Note", + description: "Additional note for the time entry", + optional: true, + }, + isBillable: { + type: "boolean", + label: "Is Billable", + description: "Whether the time entry is billable", + optional: true, + }, + isInvoiced: { + type: "boolean", + label: "Is Invoiced", + description: "Whether the time entry has been invoiced", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://app.tmetric.com/api/v3"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + Authorization: `Bearer ${this.$auth.api_token}`, + ...headers, + }, + }); + }, + + async createTimeEntry({ + accountId, ...args + }) { + return this._makeRequest({ + path: `/accounts/${accountId}/timeentries`, + method: "post", + ...args, + }); + }, + async deleteTimeEntry({ + accountId, timeEntryId, ...args + }) { + return this._makeRequest({ + path: `/accounts/${accountId}/timeentries/${timeEntryId}`, + method: "delete", + ...args, + }); + }, + async modifyTimeEntry({ + accountId, timeEntryId, ...args + }) { + return this._makeRequest({ + path: `/accounts/${accountId}/timeentries/${timeEntryId}`, + method: "put", + ...args, + }); + }, + async getTimeEntries({ + accountId, ...args + }) { + return this._makeRequest({ + path: `/accounts/${accountId}/timeentries`, + ...args, + }); + }, + async getUser(args = {}) { + return this._makeRequest({ + path: "/user", + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2b67664fbbfe..80d9ea1d2412a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7106,8 +7106,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/hybrid_analysis: - specifiers: {} + components/hybrid_analysis: {} components/hygraph: {} @@ -15185,7 +15184,11 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/tmetric: {} + components/tmetric: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/todoist: dependencies: @@ -16428,8 +16431,7 @@ importers: components/wicked_reports: {} - components/wics: - specifiers: {} + components/wics: {} components/widgetform: dependencies: