@pipedream/toggl 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/actions/get-current-time-entry/get-current-time-entry.mjs +21 -0
- package/actions/get-time-entries/get-time-entries.mjs +21 -0
- package/actions/get-time-entry/get-time-entry.mjs +28 -0
- package/common/constants.mjs +6 -0
- package/package.json +21 -0
- package/sources/common/base.mjs +79 -0
- package/sources/common/constants.mjs +62 -0
- package/sources/new-start-time-entry/new-start-time-entry.mjs +34 -0
- package/sources/new-time-entry/new-time-entry.mjs +34 -0
- package/sources/new-update-time-entry/new-update-time-entry.mjs +20 -0
- package/sources/new-webhook-event/new-webhook-event.mjs +36 -0
- package/toggl.app.mjs +103 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2020 Pipedream, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import toggl from "../../toggl.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "Get Current Time Entry",
|
|
5
|
+
version: "0.0.1",
|
|
6
|
+
key: "toggl-get-current-time-entry",
|
|
7
|
+
description: "Get the time entry that is running now. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#get-running-time-entry)",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
toggl,
|
|
11
|
+
},
|
|
12
|
+
async run({ $ }) {
|
|
13
|
+
const response = await this.toggl.getCurrentTimeEntry({
|
|
14
|
+
$,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
response && $.export("summary", "Successfully retrieved current time entry");
|
|
18
|
+
|
|
19
|
+
return response;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import toggl from "../../toggl.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "Get Time Entries",
|
|
5
|
+
version: "0.0.1",
|
|
6
|
+
key: "toggl-get-time-entries",
|
|
7
|
+
description: "Get the last thousand time entries. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#get-time-entries-started-in-a-specific-time-range)",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
toggl,
|
|
11
|
+
},
|
|
12
|
+
async run({ $ }) {
|
|
13
|
+
const response = await this.toggl.getTimeEntries({
|
|
14
|
+
$,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
response && $.export("summary", "Successfully retrieved time entries");
|
|
18
|
+
|
|
19
|
+
return response;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import toggl from "../../toggl.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "Get Time Entry",
|
|
5
|
+
version: "0.0.1",
|
|
6
|
+
key: "toggl-get-time-entry",
|
|
7
|
+
description: "Get details about a specific time entry. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#get-time-entry-details)",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
toggl,
|
|
11
|
+
timeEntryId: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
toggl,
|
|
14
|
+
"timeEntryId",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
async run({ $ }) {
|
|
19
|
+
const response = await this.toggl.getTimeEntry({
|
|
20
|
+
$,
|
|
21
|
+
timeEntryId: this.timeEntryId,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
response && $.export("summary", "Successfully retrieved time entry");
|
|
25
|
+
|
|
26
|
+
return response;
|
|
27
|
+
},
|
|
28
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipedream/toggl",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Pipedream Toggl Components",
|
|
5
|
+
"main": "toggl.app.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pipedream",
|
|
8
|
+
"toggl"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://pipedream.com/apps/toggl",
|
|
11
|
+
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@pipedream/platform": "^0.10.0",
|
|
19
|
+
"toggl-api": "^1.0.2"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import toggl from "../../toggl.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
props: {
|
|
5
|
+
toggl,
|
|
6
|
+
workspaceId: {
|
|
7
|
+
propDefinition: [
|
|
8
|
+
toggl,
|
|
9
|
+
"workspaceId",
|
|
10
|
+
],
|
|
11
|
+
},
|
|
12
|
+
db: "$.service.db",
|
|
13
|
+
http: {
|
|
14
|
+
type: "$.interface.http",
|
|
15
|
+
customResponse: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
methods: {
|
|
19
|
+
async _respond(event) {
|
|
20
|
+
const { body } = event;
|
|
21
|
+
|
|
22
|
+
await this.http.respond({
|
|
23
|
+
status: 200,
|
|
24
|
+
body: {
|
|
25
|
+
validation_code: body.validation_code,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
_getWebhookId() {
|
|
30
|
+
return this.db.get("webhookId");
|
|
31
|
+
},
|
|
32
|
+
_setWebhookId(webhookId) {
|
|
33
|
+
this.db.set("webhookId", webhookId);
|
|
34
|
+
},
|
|
35
|
+
_getAction() {
|
|
36
|
+
throw new Error("_getAction not implemented");
|
|
37
|
+
},
|
|
38
|
+
_getEntity() {
|
|
39
|
+
throw new Error("_getEntity not implemented");
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
hooks: {
|
|
43
|
+
async activate() {
|
|
44
|
+
const response = await this.toggl.createWebhook({
|
|
45
|
+
workspaceId: this.workspaceId,
|
|
46
|
+
data: {
|
|
47
|
+
url_callback: this.http.endpoint,
|
|
48
|
+
event_filters: [
|
|
49
|
+
{
|
|
50
|
+
entity: this._getEntity(),
|
|
51
|
+
action: this._getAction(),
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this._setWebhookId(response.subscription_id);
|
|
58
|
+
},
|
|
59
|
+
async deactivate() {
|
|
60
|
+
const webhookId = this._getWebhookId();
|
|
61
|
+
await this.toggl.removeWebhook({
|
|
62
|
+
workspaceId: this.workspaceId,
|
|
63
|
+
webhookId,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
async run(event) {
|
|
68
|
+
const { body } = event;
|
|
69
|
+
|
|
70
|
+
await this._respond(event);
|
|
71
|
+
if (body.payload === "ping") return;
|
|
72
|
+
|
|
73
|
+
this.$emit(body, {
|
|
74
|
+
id: body.event_id,
|
|
75
|
+
summary: `New ${body.metadata.model} ${body.metadata.action} with id ${body.payload.id}`,
|
|
76
|
+
ts: Date.parse(body.created_at),
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
WEBHOOK_ENTITIES: [
|
|
3
|
+
{
|
|
4
|
+
label: "All",
|
|
5
|
+
value: "*",
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
label: "Client",
|
|
9
|
+
value: "client",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
label: "Project",
|
|
13
|
+
value: "project",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: "Project Group",
|
|
17
|
+
value: "project_group",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: "Project User",
|
|
21
|
+
value: "project_user",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: "Tag",
|
|
25
|
+
value: "tag",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: "Task",
|
|
29
|
+
value: "task",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: "Time Entry",
|
|
33
|
+
value: "time_entry",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: "Workspace",
|
|
37
|
+
value: "workspace",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: "Workspace User",
|
|
41
|
+
value: "workspace_user",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
WEBHOOK_ACTIONS: [
|
|
45
|
+
{
|
|
46
|
+
label: "All",
|
|
47
|
+
value: "*",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: "Created",
|
|
51
|
+
value: "created",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
label: "Updated",
|
|
55
|
+
value: "updated",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: "Deleted",
|
|
59
|
+
value: "deleted",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import base from "../common/base.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...base,
|
|
5
|
+
name: "New Start Time Entry (Instant)",
|
|
6
|
+
version: "0.0.1",
|
|
7
|
+
key: "toggl-new-start-time-entry",
|
|
8
|
+
description: "Emit new event when a time entry is started. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)",
|
|
9
|
+
type: "source",
|
|
10
|
+
dedupe: "unique",
|
|
11
|
+
methods: {
|
|
12
|
+
...base.methods,
|
|
13
|
+
_getAction() {
|
|
14
|
+
return "created";
|
|
15
|
+
},
|
|
16
|
+
_getEntity() {
|
|
17
|
+
return "time_entry";
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
async run(event) {
|
|
21
|
+
const { body } = event;
|
|
22
|
+
|
|
23
|
+
await this._respond(event);
|
|
24
|
+
if (body.payload === "ping") return;
|
|
25
|
+
|
|
26
|
+
if (!body.payload.stop) {
|
|
27
|
+
this.$emit(body, {
|
|
28
|
+
id: body.event_id,
|
|
29
|
+
summary: `New time_entry started with id ${body.payload.id}`,
|
|
30
|
+
ts: Date.parse(body.created_at),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import base from "../common/base.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...base,
|
|
5
|
+
name: "New Time Entry (Instant)",
|
|
6
|
+
version: "0.0.1",
|
|
7
|
+
key: "toggl-new-time-entry",
|
|
8
|
+
description: "Emit new event when a time entry is created. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)",
|
|
9
|
+
type: "source",
|
|
10
|
+
dedupe: "unique",
|
|
11
|
+
methods: {
|
|
12
|
+
...base.methods,
|
|
13
|
+
_getAction() {
|
|
14
|
+
return "updated";
|
|
15
|
+
},
|
|
16
|
+
_getEntity() {
|
|
17
|
+
return "time_entry";
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
async run(event) {
|
|
21
|
+
const { body } = event;
|
|
22
|
+
|
|
23
|
+
await this._respond(event);
|
|
24
|
+
if (body.payload === "ping") return;
|
|
25
|
+
|
|
26
|
+
if (body.payload.stop) {
|
|
27
|
+
this.$emit(body, {
|
|
28
|
+
id: body.event_id,
|
|
29
|
+
summary: `New time_entry created with id ${body.payload.id}`,
|
|
30
|
+
ts: Date.parse(body.created_at),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import base from "../common/base.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...base,
|
|
5
|
+
name: "New Update Time Entry (Instant)",
|
|
6
|
+
version: "0.0.1",
|
|
7
|
+
key: "toggl-new-update-time-entry",
|
|
8
|
+
description: "Emit new event when a time entry is updated. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)",
|
|
9
|
+
type: "source",
|
|
10
|
+
dedupe: "unique",
|
|
11
|
+
methods: {
|
|
12
|
+
...base.methods,
|
|
13
|
+
_getAction() {
|
|
14
|
+
return "updated";
|
|
15
|
+
},
|
|
16
|
+
_getEntity() {
|
|
17
|
+
return "time_entry";
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import base from "../common/base.mjs";
|
|
2
|
+
import constants from "../common/constants.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...base,
|
|
6
|
+
name: "New Webhook Event (Instant)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
key: "toggl-new-webhook-event",
|
|
9
|
+
description: "Emit new event on receive a webhook event. [See docs here](https://github.com/toggl/toggl_api_docs/blob/master/webhooks.md)",
|
|
10
|
+
type: "source",
|
|
11
|
+
dedupe: "unique",
|
|
12
|
+
props: {
|
|
13
|
+
...base.props,
|
|
14
|
+
entity: {
|
|
15
|
+
label: "Entity",
|
|
16
|
+
description: "The entity you want to listen the events",
|
|
17
|
+
type: "string",
|
|
18
|
+
options: constants.WEBHOOK_ENTITIES,
|
|
19
|
+
},
|
|
20
|
+
action: {
|
|
21
|
+
label: "Action",
|
|
22
|
+
description: "The action you want to listen the events",
|
|
23
|
+
type: "string",
|
|
24
|
+
options: constants.WEBHOOK_ACTIONS,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
methods: {
|
|
28
|
+
...base.methods,
|
|
29
|
+
_getAction() {
|
|
30
|
+
return this.action;
|
|
31
|
+
},
|
|
32
|
+
_getEntity() {
|
|
33
|
+
return this.entity;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
package/toggl.app.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
import constants from "./common/constants.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
type: "app",
|
|
6
|
+
app: "toggl",
|
|
7
|
+
propDefinitions: {
|
|
8
|
+
timeEntryId: {
|
|
9
|
+
label: "Time Entry ID",
|
|
10
|
+
description: "The time entry ID",
|
|
11
|
+
type: "integer",
|
|
12
|
+
async options({ page }) {
|
|
13
|
+
const timeEntries = await this.getTimeEntries({
|
|
14
|
+
params: {
|
|
15
|
+
page: page + 1,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return timeEntries.map((timeEntry) => ({
|
|
20
|
+
label: timeEntry.description ?? `Duration: ${timeEntry.duration}`,
|
|
21
|
+
value: timeEntry.id,
|
|
22
|
+
}));
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
workspaceId: {
|
|
26
|
+
label: "Workspace Id",
|
|
27
|
+
description: "The workspace ID",
|
|
28
|
+
type: "integer",
|
|
29
|
+
async options({ page }) {
|
|
30
|
+
const workspaces = await this.getWorkspaces({
|
|
31
|
+
params: {
|
|
32
|
+
page: page + 1,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return workspaces.map((workspace) => ({
|
|
37
|
+
label: workspace.name,
|
|
38
|
+
value: workspace.id,
|
|
39
|
+
}));
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
methods: {
|
|
44
|
+
_apiToken() {
|
|
45
|
+
return this.$auth.api_token;
|
|
46
|
+
},
|
|
47
|
+
_apiUrl(apiVersion) {
|
|
48
|
+
return constants.API_BASE_URL_VERSIONS[apiVersion];
|
|
49
|
+
},
|
|
50
|
+
async _makeRequest(apiVersion, path, options = {}, $ = this) {
|
|
51
|
+
return axios($, {
|
|
52
|
+
url: `${this._apiUrl(apiVersion)}/${path}`,
|
|
53
|
+
auth: {
|
|
54
|
+
username: this._apiToken(),
|
|
55
|
+
password: "api_token",
|
|
56
|
+
},
|
|
57
|
+
...options,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
async createWebhook({
|
|
61
|
+
workspaceId, data,
|
|
62
|
+
}) {
|
|
63
|
+
return this._makeRequest("v1", `subscriptions/${workspaceId}`, {
|
|
64
|
+
method: "post",
|
|
65
|
+
data: {
|
|
66
|
+
...data,
|
|
67
|
+
enabled: true,
|
|
68
|
+
description: `Pipedream webhook created at ${new Date().toISOString()}`,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async removeWebhook({
|
|
73
|
+
workspaceId, webhookId,
|
|
74
|
+
}) {
|
|
75
|
+
return this._makeRequest("v1", `subscriptions/${workspaceId}/${webhookId}`, {
|
|
76
|
+
method: "delete",
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
async getWorkspaces({ $ } = {}) {
|
|
80
|
+
return this._makeRequest("v8", "workspaces", {}, $);
|
|
81
|
+
},
|
|
82
|
+
async getCurrentTimeEntry({ $ } = {}) {
|
|
83
|
+
return this._makeRequest("v8", "time_entries/current", {}, $);
|
|
84
|
+
},
|
|
85
|
+
async getTimeEntries({
|
|
86
|
+
params, $,
|
|
87
|
+
} = {}) {
|
|
88
|
+
return this._makeRequest("v8", "time_entries", {
|
|
89
|
+
params: {
|
|
90
|
+
...params,
|
|
91
|
+
per_page: 1000,
|
|
92
|
+
},
|
|
93
|
+
}, $);
|
|
94
|
+
},
|
|
95
|
+
async getTimeEntry({
|
|
96
|
+
timeEntryId, $,
|
|
97
|
+
} = {}) {
|
|
98
|
+
const { data } = await this._makeRequest("v8", `time_entries/${timeEntryId}`, {}, $);
|
|
99
|
+
|
|
100
|
+
return data;
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|