@pipedream/asana 0.3.3 → 0.3.5
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/actions/add-task-to-section/add-task-to-section.mjs +79 -0
- package/actions/common/common.mjs +26 -0
- package/actions/common/constants.mjs +22 -0
- package/actions/create-project/create-project.mjs +142 -0
- package/actions/create-subtask/create-subtask.mjs +132 -0
- package/actions/create-task/create-task.mjs +147 -0
- package/actions/create-task-comment/create-task-comment.mjs +66 -0
- package/actions/delete-task/delete-task.mjs +34 -0
- package/actions/find-task-by-id/find-task-by-id.mjs +32 -0
- package/actions/search-projects/search-projects.mjs +50 -0
- package/actions/search-sections/search-sections.mjs +25 -0
- package/actions/search-tasks/search-tasks.mjs +74 -0
- package/actions/search-user-projects/search-user-projects.mjs +47 -0
- package/actions/update-task/update-task.mjs +125 -0
- package/asana.app.mjs +377 -0
- package/package.json +19 -19
- package/sources/common/common.mjs +75 -0
- package/sources/new-completed-task/new-completed-task.mjs +60 -0
- package/sources/new-project/new-project.mjs +50 -0
- package/sources/new-story/new-story.mjs +57 -0
- package/sources/new-subtask/new-subtask.mjs +72 -0
- package/sources/new-tag/new-tag.mjs +45 -0
- package/sources/new-task/new-task.mjs +56 -0
- package/sources/new-team/new-team.mjs +42 -0
- package/sources/new-user/new-user.mjs +50 -0
- package/sources/new-workspace/new-workspace.mjs +34 -0
- package/sources/tag-added-to-task/tag-added-to-task.mjs +71 -0
- package/sources/task-updated-in-project/task-updated-in-project.mjs +72 -0
- package/asana.app.js +0 -190
- package/sources/completed-task/completed-task.js +0 -76
- package/sources/new-project/new-project.js +0 -68
- package/sources/new-story/new-story.js +0 -75
- package/sources/new-subtask/new-subtask.js +0 -84
- package/sources/new-task-in-project/new-task-in-project.js +0 -75
- package/sources/new-team/new-team.js +0 -32
- package/sources/new-user/new-user.js +0 -68
- package/sources/new-workspace/new-workspace.js +0 -31
- package/sources/tag-added-to-task/tag-added-to-task.js +0 -84
- package/sources/updated-task-in-project/updated-task-in-project.js +0 -83
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import common from "../common/common.mjs";
|
|
2
|
+
const { asana } = common.props;
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "asana-task-updated-in-project",
|
|
7
|
+
type: "source",
|
|
8
|
+
name: "Task Updated In Project (Instant)",
|
|
9
|
+
description: "Emit new event for each update to a task.",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
dedupe: "unique",
|
|
12
|
+
props: {
|
|
13
|
+
...common.props,
|
|
14
|
+
project: {
|
|
15
|
+
label: "Project",
|
|
16
|
+
description: "Gid of a project.",
|
|
17
|
+
type: "string",
|
|
18
|
+
propDefinition: [
|
|
19
|
+
asana,
|
|
20
|
+
"projects",
|
|
21
|
+
(c) => ({
|
|
22
|
+
workspace: c.workspace,
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
tasks: {
|
|
27
|
+
propDefinition: [
|
|
28
|
+
asana,
|
|
29
|
+
"tasks",
|
|
30
|
+
(c) => ({
|
|
31
|
+
projects: c.project,
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
methods: {
|
|
37
|
+
...common.methods,
|
|
38
|
+
getWebhookFilter() {
|
|
39
|
+
return {
|
|
40
|
+
filters: [
|
|
41
|
+
{
|
|
42
|
+
action: "changed",
|
|
43
|
+
resource_type: "task",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
resource: this.project,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
async emitEvent(event) {
|
|
50
|
+
const { body } = event;
|
|
51
|
+
if (!body || !body.events) return;
|
|
52
|
+
|
|
53
|
+
const tasks = this.db.get("tasks");
|
|
54
|
+
|
|
55
|
+
for (const e of body.events) {
|
|
56
|
+
// This conditional ignore when Asana fire a subtask update event
|
|
57
|
+
if (e.parent && e.parent.resource_type === "task") continue;
|
|
58
|
+
|
|
59
|
+
if (!tasks || tasks.length <= 0 || Object.keys(tasks).length <= 0 ||
|
|
60
|
+
tasks.includes(e.resource.gid)) {
|
|
61
|
+
const task = await this.asana.getTask(e.resource.gid);
|
|
62
|
+
|
|
63
|
+
this.$emit(task, {
|
|
64
|
+
id: task.gid,
|
|
65
|
+
summary: task.name,
|
|
66
|
+
ts: Date.now(),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
package/asana.app.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
const axios = require("axios");
|
|
2
|
-
const crypto = require("crypto");
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
type: "app",
|
|
6
|
-
app: "asana",
|
|
7
|
-
propDefinitions: {
|
|
8
|
-
workspaceId: {
|
|
9
|
-
type: "string",
|
|
10
|
-
label: "Workspace",
|
|
11
|
-
optional: false,
|
|
12
|
-
async options(opts) {
|
|
13
|
-
const workspaces = await this.getWorkspaces();
|
|
14
|
-
return workspaces.map((workspace) => {
|
|
15
|
-
return {
|
|
16
|
-
label: workspace.name,
|
|
17
|
-
value: workspace.gid,
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
projectId: {
|
|
23
|
-
type: "string",
|
|
24
|
-
label: "Project",
|
|
25
|
-
optional: false,
|
|
26
|
-
async options(opts) {
|
|
27
|
-
const projects = await this.getProjects(opts.workspaceId);
|
|
28
|
-
return projects.map((project) => {
|
|
29
|
-
return {
|
|
30
|
-
label: project.name,
|
|
31
|
-
value: project.gid,
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
taskIds: {
|
|
37
|
-
type: "string[]",
|
|
38
|
-
label: "Tasks",
|
|
39
|
-
async options(opts) {
|
|
40
|
-
const tasks = await this.getTasks(opts.projectId);
|
|
41
|
-
return tasks.map((task) => {
|
|
42
|
-
return { label: task.name, value: task.gid };
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
organizationId: {
|
|
47
|
-
type: "string",
|
|
48
|
-
label: "Organization",
|
|
49
|
-
optional: false,
|
|
50
|
-
async options(opts) {
|
|
51
|
-
const organizations = await this.getOrganizations();
|
|
52
|
-
return organizations.map((organization) => {
|
|
53
|
-
return {
|
|
54
|
-
label: organization.name,
|
|
55
|
-
value: organization.gid,
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
methods: {
|
|
62
|
-
async _getBaseUrl() {
|
|
63
|
-
return "https://app.asana.com/api/1.0"
|
|
64
|
-
},
|
|
65
|
-
async _getHeaders() {
|
|
66
|
-
return {
|
|
67
|
-
Accept: "application/json",
|
|
68
|
-
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
async _makeRequest(endpoint) {
|
|
72
|
-
config = {
|
|
73
|
-
url: `${await this._getBaseUrl()}/${endpoint}`,
|
|
74
|
-
headers: {
|
|
75
|
-
Accept: "application/json",
|
|
76
|
-
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
try {
|
|
80
|
-
return await axios(config);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
console.log(err);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
async _getAuthorizationHeader({ data, method, url, headers }) {
|
|
86
|
-
return await axios({
|
|
87
|
-
method: "POST",
|
|
88
|
-
url: `${await this._getBaseUrl()}/webhooks`,
|
|
89
|
-
data: data.body,
|
|
90
|
-
headers,
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
async createHook(body) {
|
|
94
|
-
const config = {
|
|
95
|
-
method: "post",
|
|
96
|
-
url: `${await this._getBaseUrl()}/webhooks`,
|
|
97
|
-
headers: {
|
|
98
|
-
"Content-Type": "applicaton/json",
|
|
99
|
-
Accept: "application/json",
|
|
100
|
-
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
|
|
101
|
-
},
|
|
102
|
-
data: {
|
|
103
|
-
body,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
const authorization = await this._getAuthorizationHeader(config);
|
|
107
|
-
config.headers.authorization = authorization;
|
|
108
|
-
try {
|
|
109
|
-
await axios(config);
|
|
110
|
-
} catch (err) {
|
|
111
|
-
console.log(err);
|
|
112
|
-
}
|
|
113
|
-
return authorization.data;
|
|
114
|
-
},
|
|
115
|
-
async deleteHook(hookId) {
|
|
116
|
-
const config = {
|
|
117
|
-
method: "delete",
|
|
118
|
-
url: `${await this._getBaseUrl()}/webhooks/${hookId}`,
|
|
119
|
-
headers: await this._getHeaders(),
|
|
120
|
-
};
|
|
121
|
-
try {
|
|
122
|
-
await axios(config);
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.log(err);
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
async verifyAsanaWebhookRequest(request) {
|
|
128
|
-
let secret = this.$auth.oauth_refresh_token;
|
|
129
|
-
var base64Digest = function (s) {
|
|
130
|
-
return crypto.createHmac("sha1", secret).update(s).digest("base64");
|
|
131
|
-
};
|
|
132
|
-
var content = JSON.stringify(request.body);
|
|
133
|
-
var doubleHash = base64Digest(content);
|
|
134
|
-
var headerHash = request.headers["x-hook-secret"];
|
|
135
|
-
return doubleHash === headerHash;
|
|
136
|
-
},
|
|
137
|
-
async getWorkspace(workspaceId) {
|
|
138
|
-
return (await this._makeRequest(`workspaces/${workspaceId}`)).data.data;
|
|
139
|
-
},
|
|
140
|
-
async getWorkspaces() {
|
|
141
|
-
return (await this._makeRequest("workspaces")).data.data;
|
|
142
|
-
},
|
|
143
|
-
async getOrganizations() {
|
|
144
|
-
const organizations = [];
|
|
145
|
-
const workspaces = await this.getWorkspaces();
|
|
146
|
-
for (const workspace of workspaces) {
|
|
147
|
-
let w = await this.getWorkspace(workspace.gid);
|
|
148
|
-
if (w.is_organization) organizations.push(w);
|
|
149
|
-
}
|
|
150
|
-
return organizations;
|
|
151
|
-
},
|
|
152
|
-
async getProject(projectId) {
|
|
153
|
-
return (await this._makeRequest(`projects/${projectId}`)).data.data;
|
|
154
|
-
},
|
|
155
|
-
async getProjects(workspaceId) {
|
|
156
|
-
return (await this._makeRequest(`projects?workspace=${workspaceId}`)).data.data;
|
|
157
|
-
},
|
|
158
|
-
async getStory(storyId) {
|
|
159
|
-
return (await this._makeRequest(`stories/${storyId}`)).data.data;
|
|
160
|
-
},
|
|
161
|
-
async getTask(taskId) {
|
|
162
|
-
return (await this._makeRequest(`tasks/${taskId}`)).data.data;
|
|
163
|
-
},
|
|
164
|
-
async getTasks(projectId) {
|
|
165
|
-
let incompleteTasks = [];
|
|
166
|
-
const tasks = (await this._makeRequest(`projects/${projectId}/tasks`)).data.data;
|
|
167
|
-
for (const task of tasks) {
|
|
168
|
-
let t = await this.getTask(task.gid);
|
|
169
|
-
if (t.completed == false) incompleteTasks.push(task);
|
|
170
|
-
}
|
|
171
|
-
return incompleteTasks;
|
|
172
|
-
},
|
|
173
|
-
async getTag(tagId) {
|
|
174
|
-
return (await this._makeRequest(`tags/${tagId}`)).data.data;
|
|
175
|
-
},
|
|
176
|
-
async getTeam(teamId) {
|
|
177
|
-
return (await this._makeRequest(`teams/${teamId}`)).data.data;
|
|
178
|
-
},
|
|
179
|
-
async getTeams(organizationId) {
|
|
180
|
-
return (await this._makeRequest(`organizations/${organizationId}/teams`)).data.data;
|
|
181
|
-
},
|
|
182
|
-
async getUser(userId) {
|
|
183
|
-
|
|
184
|
-
return (await this._makeRequest(`users/${userId}`)).data.data;
|
|
185
|
-
},
|
|
186
|
-
async getUsers(workspaceId) {
|
|
187
|
-
return (await this._makeRequest(`workspaces/${workspaceId}/users`)).data.data;
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const asana = require("../../asana.app.js");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "Task Completed (Instant)",
|
|
5
|
-
key: "asana-completed-task",
|
|
6
|
-
description: "Emits an event for each task completed in a project.",
|
|
7
|
-
version: "0.0.1",
|
|
8
|
-
dedupe: "unique",
|
|
9
|
-
props: {
|
|
10
|
-
asana,
|
|
11
|
-
workspaceId: { propDefinition: [asana, "workspaceId"] },
|
|
12
|
-
projectId: {
|
|
13
|
-
propDefinition: [
|
|
14
|
-
asana,
|
|
15
|
-
"projectId",
|
|
16
|
-
(c) => ({ workspaceId: c.workspaceId }),
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
db: "$.service.db",
|
|
20
|
-
http: {
|
|
21
|
-
type: "$.interface.http",
|
|
22
|
-
customResponse: true,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
hooks: {
|
|
27
|
-
async activate() {
|
|
28
|
-
const body = {
|
|
29
|
-
data: {
|
|
30
|
-
filters: [
|
|
31
|
-
{
|
|
32
|
-
action: "changed",
|
|
33
|
-
fields: ["completed"],
|
|
34
|
-
resource_type: "task",
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
resource: this.projectId,
|
|
38
|
-
target: this.http.endpoint,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
const resp = await this.asana.createHook(body);
|
|
42
|
-
this.db.set("hookId", resp.data.gid);
|
|
43
|
-
},
|
|
44
|
-
async deactivate() {
|
|
45
|
-
console.log(this.db.get("hookId"));
|
|
46
|
-
await this.asana.deleteHook(this.db.get("hookId"));
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
async run(event) {
|
|
51
|
-
// validate signature
|
|
52
|
-
if (!this.asana.verifyAsanaWebhookRequest(event))
|
|
53
|
-
return;
|
|
54
|
-
|
|
55
|
-
this.http.respond({
|
|
56
|
-
status: 200,
|
|
57
|
-
headers: {
|
|
58
|
-
"x-hook-secret": event.headers["x-hook-secret"],
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const { body } = event;
|
|
63
|
-
if (!body || !body.events) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
for (const e of body.events) {
|
|
68
|
-
let task = await this.asana.getTask(e.resource.gid);
|
|
69
|
-
this.$emit(task, {
|
|
70
|
-
id: task.gid,
|
|
71
|
-
summary: task.name,
|
|
72
|
-
ts: Date.now(),
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const asana = require("../../asana.app.js");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "Project Added To Workspace (Instant)",
|
|
5
|
-
key: "asana-new-project",
|
|
6
|
-
description: "Emits an event for each new project added to a workspace.",
|
|
7
|
-
version: "0.0.2",
|
|
8
|
-
dedupe: "unique",
|
|
9
|
-
props: {
|
|
10
|
-
asana,
|
|
11
|
-
workspaceId: { propDefinition: [asana, "workspaceId"] },
|
|
12
|
-
db: "$.service.db",
|
|
13
|
-
http: {
|
|
14
|
-
type: "$.interface.http",
|
|
15
|
-
customResponse: true,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
hooks: {
|
|
20
|
-
async activate() {
|
|
21
|
-
const body = {
|
|
22
|
-
data: {
|
|
23
|
-
filters: [
|
|
24
|
-
{
|
|
25
|
-
action: "added",
|
|
26
|
-
resource_type: "project",
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
resource: this.workspaceId,
|
|
30
|
-
target: this.http.endpoint,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
const resp = await this.asana.createHook(body);
|
|
34
|
-
this.db.set("hookId", resp.data.gid);
|
|
35
|
-
},
|
|
36
|
-
async deactivate() {
|
|
37
|
-
console.log(this.db.get("hookId"));
|
|
38
|
-
await this.asana.deleteHook(this.db.get("hookId"));
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
async run(event) {
|
|
43
|
-
// validate signature
|
|
44
|
-
if (!this.asana.verifyAsanaWebhookRequest(event))
|
|
45
|
-
return;
|
|
46
|
-
|
|
47
|
-
this.http.respond({
|
|
48
|
-
status: 200,
|
|
49
|
-
headers: {
|
|
50
|
-
"x-hook-secret": event.headers["x-hook-secret"],
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const { body } = event;
|
|
55
|
-
if (!body || !body.events) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (const e of body.events) {
|
|
60
|
-
let project = await this.asana.getProject(e.resource.gid);
|
|
61
|
-
this.$emit(project, {
|
|
62
|
-
id: project.gid,
|
|
63
|
-
summary: project.name,
|
|
64
|
-
ts: Date.now(),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
const asana = require("../../asana.app.js");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "Story Added To Project (Instant)",
|
|
5
|
-
key: "asana-new-story",
|
|
6
|
-
description: "Emits an event for each story added to a project.",
|
|
7
|
-
version: "0.0.2",
|
|
8
|
-
dedupe: "unique",
|
|
9
|
-
props: {
|
|
10
|
-
asana,
|
|
11
|
-
workspaceId: { propDefinition: [asana, "workspaceId"] },
|
|
12
|
-
projectId: {
|
|
13
|
-
propDefinition: [
|
|
14
|
-
asana,
|
|
15
|
-
"projectId",
|
|
16
|
-
(c) => ({ workspaceId: c.workspaceId }),
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
db: "$.service.db",
|
|
20
|
-
http: {
|
|
21
|
-
type: "$.interface.http",
|
|
22
|
-
customResponse: true,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
hooks: {
|
|
27
|
-
async activate() {
|
|
28
|
-
const body = {
|
|
29
|
-
data: {
|
|
30
|
-
filters: [
|
|
31
|
-
{
|
|
32
|
-
action: "added",
|
|
33
|
-
resource_type: "story",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
resource: this.projectId,
|
|
37
|
-
target: this.http.endpoint,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const resp = await this.asana.createHook(body);
|
|
41
|
-
this.db.set("hookId", resp.data.gid);
|
|
42
|
-
},
|
|
43
|
-
async deactivate() {
|
|
44
|
-
console.log(this.db.get("hookId"));
|
|
45
|
-
await this.asana.deleteHook(this.db.get("hookId"));
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
async run(event) {
|
|
50
|
-
// validate signature
|
|
51
|
-
if (!this.asana.verifyAsanaWebhookRequest(event))
|
|
52
|
-
return;
|
|
53
|
-
|
|
54
|
-
this.http.respond({
|
|
55
|
-
status: 200,
|
|
56
|
-
headers: {
|
|
57
|
-
"x-hook-secret": event.headers["x-hook-secret"],
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const { body } = event;
|
|
62
|
-
if (!body || !body.events) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
for (const e of body.events) {
|
|
67
|
-
let story = await this.asana.getStory(e.resource.gid);
|
|
68
|
-
this.$emit(story, {
|
|
69
|
-
id: story.gid,
|
|
70
|
-
summary: story.text,
|
|
71
|
-
ts: Date.now(),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
const asana = require("../../asana.app.js");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "New Subtask (Instant)",
|
|
5
|
-
key: "asana-new-subtask",
|
|
6
|
-
description: "Emits an event for each subtask added to a project.",
|
|
7
|
-
version: "0.0.2",
|
|
8
|
-
dedupe: "unique",
|
|
9
|
-
props: {
|
|
10
|
-
asana,
|
|
11
|
-
workspaceId: { propDefinition: [asana, "workspaceId"] },
|
|
12
|
-
projectId: {
|
|
13
|
-
propDefinition: [
|
|
14
|
-
asana,
|
|
15
|
-
"projectId",
|
|
16
|
-
(c) => ({ workspaceId: c.workspaceId }),
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
taskIds: {
|
|
20
|
-
propDefinition: [asana, "taskIds", (c) => ({ projectId: c.projectId })],
|
|
21
|
-
},
|
|
22
|
-
db: "$.service.db",
|
|
23
|
-
http: {
|
|
24
|
-
type: "$.interface.http",
|
|
25
|
-
customResponse: true,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
hooks: {
|
|
30
|
-
async activate() {
|
|
31
|
-
const body = {
|
|
32
|
-
data: {
|
|
33
|
-
filters: [
|
|
34
|
-
{
|
|
35
|
-
action: "added",
|
|
36
|
-
resource_subtype: "subtask",
|
|
37
|
-
resource_type: "task",
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
resource: this.projectId,
|
|
41
|
-
target: this.http.endpoint,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const resp = await this.asana.createHook(body);
|
|
45
|
-
this.db.set("hookId", resp.data.gid);
|
|
46
|
-
this.db.set("taskIds", this.taskIds);
|
|
47
|
-
},
|
|
48
|
-
async deactivate() {
|
|
49
|
-
console.log(this.db.get("hookId"));
|
|
50
|
-
await this.asana.deleteHook(this.db.get("hookId"));
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
async run(event) {
|
|
55
|
-
// validate signature
|
|
56
|
-
if (!this.asana.verifyAsanaWebhookRequest(event))
|
|
57
|
-
return;
|
|
58
|
-
|
|
59
|
-
this.http.respond({
|
|
60
|
-
status: 200,
|
|
61
|
-
headers: {
|
|
62
|
-
"x-hook-secret": event.headers["x-hook-secret"],
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const { body } = event;
|
|
67
|
-
if (!body || !body.events) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const taskIds = this.db.get("taskIds");
|
|
72
|
-
|
|
73
|
-
for (const e of body.events) {
|
|
74
|
-
if (e.parent.resource_type == "task" && (!taskIds || (taskIds.length < 0) || (Object.keys(taskIds).length === 0) || (taskIds && taskIds.includes(e.parent.gid)))) {
|
|
75
|
-
let task = await this.asana.getTask(e.resource.gid);
|
|
76
|
-
this.$emit(task, {
|
|
77
|
-
id: task.gid,
|
|
78
|
-
summary: task.name,
|
|
79
|
-
ts: Date.now(),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
const asana = require("../../asana.app.js");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "Task Added To Project (Instant)",
|
|
5
|
-
key: "asana-new-task-in-project",
|
|
6
|
-
description: "Emits an event for each new task added to a project.",
|
|
7
|
-
version: "0.0.2",
|
|
8
|
-
dedupe: "unique",
|
|
9
|
-
props: {
|
|
10
|
-
asana,
|
|
11
|
-
workspaceId: { propDefinition: [asana, "workspaceId"] },
|
|
12
|
-
projectId: {
|
|
13
|
-
propDefinition: [
|
|
14
|
-
asana,
|
|
15
|
-
"projectId",
|
|
16
|
-
(c) => ({ workspaceId: c.workspaceId }),
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
db: "$.service.db",
|
|
20
|
-
http: {
|
|
21
|
-
type: "$.interface.http",
|
|
22
|
-
customResponse: true,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
hooks: {
|
|
27
|
-
async activate() {
|
|
28
|
-
const body = {
|
|
29
|
-
data: {
|
|
30
|
-
filters: [
|
|
31
|
-
{
|
|
32
|
-
action: "added",
|
|
33
|
-
resource_type: "task",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
resource: this.projectId,
|
|
37
|
-
target: this.http.endpoint,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const resp = await this.asana.createHook(body);
|
|
41
|
-
this.db.set("hookId", resp.data.gid);
|
|
42
|
-
},
|
|
43
|
-
async deactivate() {
|
|
44
|
-
console.log(this.db.get("hookId"));
|
|
45
|
-
await this.asana.deleteHook(this.db.get("hookId"));
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
async run(event) {
|
|
50
|
-
// validate signature
|
|
51
|
-
if (!this.asana.verifyAsanaWebhookRequest(event))
|
|
52
|
-
return;
|
|
53
|
-
|
|
54
|
-
this.http.respond({
|
|
55
|
-
status: 200,
|
|
56
|
-
headers: {
|
|
57
|
-
"x-hook-secret": event.headers["x-hook-secret"],
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const { body } = event;
|
|
62
|
-
if (!body || !body.events) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
for (const e of body.events) {
|
|
67
|
-
let task = await this.asana.getTask(e.resource.gid);
|
|
68
|
-
this.$emit(task, {
|
|
69
|
-
id: task.gid,
|
|
70
|
-
summary: task.name,
|
|
71
|
-
ts: Date.now(),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const asana = require("../../asana.app.js");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "Team Added To Organization",
|
|
5
|
-
key: "asana-new-team",
|
|
6
|
-
description: "Emits an event for each team added to an organization.",
|
|
7
|
-
version: "0.0.1",
|
|
8
|
-
dedupe: "unique",
|
|
9
|
-
props: {
|
|
10
|
-
asana,
|
|
11
|
-
organizationId: { propDefinition: [asana, "organizationId"] },
|
|
12
|
-
db: "$.service.db",
|
|
13
|
-
timer: {
|
|
14
|
-
type: "$.interface.timer",
|
|
15
|
-
default: {
|
|
16
|
-
intervalSeconds: 60 * 15,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
async run(event) {
|
|
22
|
-
let results = await this.asana.getTeams(this.organizationId);
|
|
23
|
-
for (const result of results) {
|
|
24
|
-
let team = await this.asana.getTeam(result.gid);
|
|
25
|
-
this.$emit(team, {
|
|
26
|
-
id: team.gid,
|
|
27
|
-
summary: team.name,
|
|
28
|
-
ts: Date.now(),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
};
|