@pipedream/asana 0.3.1 → 0.3.4

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.
Files changed (39) hide show
  1. package/actions/add-task-to-section/add-task-to-section.mjs +79 -0
  2. package/actions/common/common.mjs +26 -0
  3. package/actions/common/constants.mjs +22 -0
  4. package/actions/create-project/create-project.mjs +142 -0
  5. package/actions/create-subtask/create-subtask.mjs +132 -0
  6. package/actions/create-task/create-task.mjs +147 -0
  7. package/actions/create-task-comment/create-task-comment.mjs +66 -0
  8. package/actions/delete-task/delete-task.mjs +34 -0
  9. package/actions/find-task-by-id/find-task-by-id.mjs +32 -0
  10. package/actions/search-projects/search-projects.mjs +50 -0
  11. package/actions/search-sections/search-sections.mjs +25 -0
  12. package/actions/search-tasks/search-tasks.mjs +74 -0
  13. package/actions/search-user-projects/search-user-projects.mjs +47 -0
  14. package/actions/update-task/update-task.mjs +125 -0
  15. package/asana.app.mjs +377 -0
  16. package/package.json +19 -19
  17. package/sources/common/common.mjs +75 -0
  18. package/sources/new-completed-task/new-completed-task.mjs +60 -0
  19. package/sources/new-project/new-project.mjs +50 -0
  20. package/sources/new-story/new-story.mjs +57 -0
  21. package/sources/new-subtask/new-subtask.mjs +72 -0
  22. package/sources/new-tag/new-tag.mjs +45 -0
  23. package/sources/new-task/new-task.mjs +56 -0
  24. package/sources/new-team/new-team.mjs +42 -0
  25. package/sources/new-user/new-user.mjs +50 -0
  26. package/sources/new-workspace/new-workspace.mjs +34 -0
  27. package/sources/tag-added-to-task/tag-added-to-task.mjs +71 -0
  28. package/sources/updated-task-in-project/updated-task-in-project.mjs +72 -0
  29. package/asana.app.js +0 -190
  30. package/sources/completed-task/completed-task.js +0 -76
  31. package/sources/new-project/new-project.js +0 -68
  32. package/sources/new-story/new-story.js +0 -75
  33. package/sources/new-subtask/new-subtask.js +0 -84
  34. package/sources/new-task-in-project/new-task-in-project.js +0 -75
  35. package/sources/new-team/new-team.js +0 -32
  36. package/sources/new-user/new-user.js +0 -68
  37. package/sources/new-workspace/new-workspace.js +0 -31
  38. package/sources/tag-added-to-task/tag-added-to-task.js +0 -84
  39. package/sources/updated-task-in-project/updated-task-in-project.js +0 -83
@@ -0,0 +1,50 @@
1
+ import asana from "../../asana.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "asana-search-projects",
6
+ version: "0.2.0",
7
+ name: "Search Projects",
8
+ description: "Finds an existing project. [See the docs here](https://developers.asana.com/docs/get-multiple-projects)",
9
+ props: {
10
+ asana,
11
+ name: {
12
+ label: "Name",
13
+ description: "The name to filter projects on.",
14
+ type: "string",
15
+ optional: true,
16
+ },
17
+ workspace: {
18
+ label: "Workspace",
19
+ description: "The workspace or organization to filter projects on.",
20
+ type: "string",
21
+ optional: true,
22
+ propDefinition: [
23
+ asana,
24
+ "workspaces",
25
+ ],
26
+ },
27
+ archived: {
28
+ label: "Archived",
29
+ description: "Only return projects whose `archived` field takes on the value of this parameter.",
30
+ type: "boolean",
31
+ optional: true,
32
+ },
33
+ },
34
+ async run({ $ }) {
35
+ const {
36
+ name,
37
+ workspace,
38
+ archived,
39
+ } = this;
40
+
41
+ const projects = await this.asana.getProjects(workspace, {
42
+ archived,
43
+ }, $);
44
+
45
+ $.export("$summary", "Successfully retrieved projects");
46
+
47
+ if (this.name) return projects.filter((project) => project.name.includes(name));
48
+ else return projects;
49
+ },
50
+ };
@@ -0,0 +1,25 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ key: "asana-search-sections",
5
+ name: "Search Sections",
6
+ description: "Searches for a section by name within a particular project. [See the docs here](https://developers.asana.com/docs/get-sections-in-a-project)",
7
+ version: "0.2.0",
8
+ type: "action",
9
+ props: {
10
+ ...common.props,
11
+ name: {
12
+ label: "Name",
13
+ description: "The name of the section to search for.",
14
+ type: "string",
15
+ },
16
+ },
17
+ async run({ $ }) {
18
+ const sections = await this.asana.getSections(this.project, $);
19
+
20
+ $.export("$summary", "Successfully retrieved sections");
21
+
22
+ if (this.name) return sections.filter((section) => section.name.includes(this.name));
23
+ else return sections;
24
+ },
25
+ };
@@ -0,0 +1,74 @@
1
+ import asana from "../../asana.app.mjs";
2
+ import common from "../common/common.mjs";
3
+
4
+ export default {
5
+ key: "asana-search-tasks",
6
+ name: "Search Tasks",
7
+ description: "Searches for a Task by name within a Project. [See the docs here](https://developers.asana.com/docs/get-multiple-tasks)",
8
+ version: "0.2.0",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ name: {
13
+ label: "Name",
14
+ description: "The task name to search for.",
15
+ type: "string",
16
+ },
17
+ assignee: {
18
+ label: "Assignee",
19
+ description: "The assignee to filter tasks on",
20
+ type: "string",
21
+ optional: true,
22
+ propDefinition: [
23
+ asana,
24
+ "users",
25
+ ],
26
+ },
27
+ section: {
28
+ label: "Section",
29
+ type: "string",
30
+ description: "The section to filter tasks on.",
31
+ optional: true,
32
+ propDefinition: [
33
+ asana,
34
+ "sections",
35
+ (c) => ({
36
+ project: c.project,
37
+ }),
38
+ ],
39
+ },
40
+ completed_since: {
41
+ label: "Completed Since",
42
+ type: "string",
43
+ description: "Only return tasks that are either incomplete or that have been completed since this time. ISO 8601 date string",
44
+ optional: true,
45
+ },
46
+ modified_since: {
47
+ label: "Modified Since",
48
+ type: "string",
49
+ description: "Only return tasks that have been modified since the given time. ISO 8601 date string",
50
+ optional: true,
51
+ },
52
+ },
53
+ async run({ $ }) {
54
+ if ((!this.workspace || !this.assignee) && !this.project && !this.section) {
55
+ throw new Error("You must specify exactly one of workspace, project, or section");
56
+ }
57
+
58
+ const tasks = await this.asana.getTasks({
59
+ params: {
60
+ assignee: this.assignee,
61
+ project: this.project,
62
+ section: this.section,
63
+ workspace: this.workspace,
64
+ completed_since: this.completed_since,
65
+ modified_since: this.modified_since,
66
+ },
67
+ }, $);
68
+
69
+ $.export("$summary", "Successfully retrieved tasks");
70
+
71
+ if (this.name) return tasks.filter((task) => task.name.includes(this.name));
72
+ else return tasks;
73
+ },
74
+ };
@@ -0,0 +1,47 @@
1
+ import asana from "../../asana.app.mjs";
2
+ import _ from "lodash";
3
+
4
+ export default {
5
+ key: "asana-search-user-projects",
6
+ name: "Get list of user projects",
7
+ description: "Return list of projects given the user and workspace gid. [See the docs here](https://developers.asana.com/docs/get-multiple-projects)",
8
+ version: "0.4.0",
9
+ type: "action",
10
+ props: {
11
+ asana,
12
+ workspace: {
13
+ label: "Workspace",
14
+ description: "Gid of a workspace.",
15
+ type: "string",
16
+ propDefinition: [
17
+ asana,
18
+ "workspaces",
19
+ ],
20
+ optional: true,
21
+ },
22
+ user: {
23
+ label: "User",
24
+ type: "string",
25
+ description: "GID of a user",
26
+ propDefinition: [
27
+ asana,
28
+ "users",
29
+ ],
30
+ },
31
+ },
32
+ async run({ $ }) {
33
+ let projects = await this.asana.getProjects(this.workspace, {}, $);
34
+
35
+ projects = projects.filter(async (project) => {
36
+ project = await this.asana.getProject(project.gid);
37
+
38
+ return project.members && !!_.find(project.members, {
39
+ gid: this.user,
40
+ });
41
+ });
42
+
43
+ $.export("$summary", "Successfully retrieved projects of user");
44
+
45
+ return projects;
46
+ },
47
+ };
@@ -0,0 +1,125 @@
1
+ import asana from "../../asana.app.mjs";
2
+ import common from "../common/common.mjs";
3
+
4
+ export default {
5
+ key: "asana-update-task",
6
+ name: "Update Task",
7
+ description: "Updates a specific and existing task. [See the docs here](https://developers.asana.com/docs/update-a-task)",
8
+ version: "0.3.0",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ task_gid: {
13
+ label: "Task GID",
14
+ description: "The ID of the task to update",
15
+ type: "string",
16
+ propDefinition: [
17
+ asana,
18
+ "tasks",
19
+ (c) => ({
20
+ project: c.project,
21
+ }),
22
+ ],
23
+ },
24
+ name: {
25
+ label: "Name",
26
+ description: "Name of the task. This is generally a short sentence fragment that fits on a line in the UI for maximum readability. However, it can be longer.",
27
+ type: "string",
28
+ },
29
+ assignee: {
30
+ label: "Assignee",
31
+ description: "Gid of a user.",
32
+ type: "string",
33
+ optional: true,
34
+ propDefinition: [
35
+ asana,
36
+ "users",
37
+ ],
38
+ },
39
+ assignee_section: {
40
+ label: "Assignee Section",
41
+ description: "The assignee section is a subdivision of a project that groups tasks together in the assignee's \"My Tasks\" list.",
42
+ type: "string",
43
+ optional: true,
44
+ propDefinition: [
45
+ asana,
46
+ "sections",
47
+ (c) => ({
48
+ project: c.project,
49
+ }),
50
+ ],
51
+ },
52
+ completed: {
53
+ label: "Completed",
54
+ description: "True if the task is currently marked complete, false if not.",
55
+ type: "boolean",
56
+ optional: true,
57
+ },
58
+ due_at: {
59
+ label: "Due At",
60
+ description: "The UTC date and time on which this task is due, or null if the task has no due time. This takes an ISO 8601 date string in UTC and should not be used together with due_on.",
61
+ type: "string",
62
+ optional: true,
63
+ },
64
+ due_on: {
65
+ label: "Due On",
66
+ description: "The localized date on which this task is due, or null if the task has no due date. This takes a date with YYYY-MM-DD format and should not be used together with due_at.",
67
+ type: "string",
68
+ optional: true,
69
+ },
70
+ html_notes: {
71
+ label: "HTML Notes",
72
+ description: "The notes of the text with formatting as HTML.",
73
+ type: "string",
74
+ optional: true,
75
+ },
76
+ notes: {
77
+ label: "Notes",
78
+ description: "Free-form textual information associated with the task (i.e. its description).",
79
+ type: "string",
80
+ optional: true,
81
+ },
82
+ start_on: {
83
+ label: "Start On",
84
+ description: "The day on which work begins for the task , or null if the task has no start date. This takes a date with YYYY-MM-DD format.",
85
+ type: "string",
86
+ optional: true,
87
+ },
88
+ custom_fields: {
89
+ label: "Custom Fields",
90
+ description: `An object where each key is a Custom Field gid and each value is an enum gid, string, or number: E.g. {
91
+ "4578152156": "Not Started",
92
+ "5678904321": "On Hold"
93
+ }`,
94
+ type: "string",
95
+ optional: true,
96
+ },
97
+ },
98
+ async run({ $ }) {
99
+ let customFields;
100
+ if (this.custom_fields) customFields = JSON.parse(this.custom_fields);
101
+
102
+ const response = await this.asana._makeRequest(`tasks/${this.task_gid}`, {
103
+ method: "put",
104
+ data: {
105
+ data: {
106
+ name: this.name,
107
+ assignee: this.assignee,
108
+ assignee_section: this.assignee_section,
109
+ completed: this.completed,
110
+ due_at: this.due_at,
111
+ due_on: this.due_on,
112
+ html_notes: this.html_notes,
113
+ notes: this.notes,
114
+ start_on: this.start_on,
115
+ workspace: this.workspace,
116
+ custom_fields: customFields,
117
+ },
118
+ },
119
+ }, $);
120
+
121
+ $.export("$summary", "Successfully updated task");
122
+
123
+ return response.data;
124
+ },
125
+ };
package/asana.app.mjs ADDED
@@ -0,0 +1,377 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "asana",
6
+ propDefinitions: {
7
+ organizations: {
8
+ label: "Organizations",
9
+ description: "List of organizations. This field use the organization GID.",
10
+ type: "string[]",
11
+ async options() {
12
+ const organizations = await this.getOrganizations();
13
+
14
+ return organizations.map((organization) => ({
15
+ label: organization.name,
16
+ value: organization.gid,
17
+ }));
18
+ },
19
+ },
20
+ workspaces: {
21
+ label: "Workspaces",
22
+ description: "List of workspaces. This field use the workspace GID.",
23
+ type: "string[]",
24
+ async options() {
25
+ const workspaces = await this.getWorkspaces();
26
+
27
+ return workspaces.map((workspace) => ({
28
+ label: workspace.name,
29
+ value: workspace.gid,
30
+ }));
31
+ },
32
+ },
33
+ teams: {
34
+ label: "Teams",
35
+ description: "List of teams. This field use the team GID.",
36
+ type: "string[]",
37
+ async options() {
38
+ const teams = await this.getTeams();
39
+
40
+ return teams.map((team) => ({
41
+ label: team.name,
42
+ value: team.gid,
43
+ }));
44
+ },
45
+ },
46
+ projects: {
47
+ label: "Projects",
48
+ description: "List of projects. This field use the project GID.",
49
+ type: "string[]",
50
+ async options({ workspace }) {
51
+ const projects = await this.getProjects(workspace);
52
+
53
+ return projects.map((tag) => ({
54
+ label: tag.name,
55
+ value: tag.gid,
56
+ }));
57
+ },
58
+ },
59
+ tags: {
60
+ label: "Tags",
61
+ description: "List of tags. This field use the tag GID.",
62
+ type: "string[]",
63
+ async options() {
64
+ const tags = await this.getTags();
65
+
66
+ return tags.map((tag) => {
67
+ return {
68
+ label: tag.name,
69
+ value: tag.gid,
70
+ };
71
+ });
72
+ },
73
+ },
74
+ users: {
75
+ label: "Users",
76
+ description: "List of users. This field use the user GID.",
77
+ type: "string[]",
78
+ async options() {
79
+ const users = await this.getUsers();
80
+
81
+ return users.map((user) => ({
82
+ label: user.name,
83
+ value: user.gid,
84
+ }));
85
+ },
86
+ },
87
+ tasks: {
88
+ label: "Tasks",
89
+ description: "List of tasks. This field use the task GID.",
90
+ type: "string[]",
91
+ async options({ project }) {
92
+ const tasks = await this.getTasks({
93
+ project,
94
+ });
95
+
96
+ return tasks.map((task) => {
97
+ return {
98
+ label: task.name,
99
+ value: task.gid,
100
+ };
101
+ });
102
+ },
103
+ },
104
+ sections: {
105
+ label: "Sections",
106
+ description: "List of sections. This field use the section GID.",
107
+ type: "string[]",
108
+ async options({ project }) {
109
+ const sections = await this.getSections(project);
110
+
111
+ return sections.map((section) => {
112
+ return {
113
+ label: section.name,
114
+ value: section.gid,
115
+ };
116
+ });
117
+ },
118
+ },
119
+ },
120
+ methods: {
121
+ /**
122
+ * Get the access token;
123
+ *
124
+ * @returns {string} The access token.
125
+ */
126
+ _accessToken() {
127
+ return this.$auth.oauth_access_token;
128
+ },
129
+ /**
130
+ * Get the base url of Asana API;
131
+ *
132
+ * @returns {string} The Asana Api base url.
133
+ */
134
+ _apiUrl() {
135
+ return "https://app.asana.com/api/1.0";
136
+ },
137
+ _headers() {
138
+ return {
139
+ Accept: "application/json",
140
+ Authorization: `Bearer ${this._accessToken()}`,
141
+ };
142
+ },
143
+ /**
144
+ * Make a requests with pre defined options.
145
+ *
146
+ * @param {string} path - The path to make the request.
147
+ * @param {object} options - A default Axios options object.
148
+ *
149
+ * @returns {string} The request result data.
150
+ */
151
+ async _makeRequest(path, options = {}, $ = this) {
152
+ return axios($, {
153
+ url: `${this._apiUrl()}/${path}`,
154
+ headers: this._headers(),
155
+ ...options,
156
+ });
157
+ },
158
+ /**
159
+ * Create a webhook
160
+ *
161
+ * @param {string} body - The body that will be send on request.
162
+ *
163
+ * @returns {object} A Asana Webhook.
164
+ */
165
+ async createWebHook(body) {
166
+ const authorization = await this._makeRequest("webhooks", {
167
+ method: "post",
168
+ data: body,
169
+ });
170
+
171
+ return authorization.data;
172
+ },
173
+ /**
174
+ * Remove a Webhook.
175
+ *
176
+ * @param {string} hookId - The Asana Webhook GID.
177
+ */
178
+ async deleteWebhook(hookId) {
179
+ await this._makeRequest(`webhooks/${hookId}`, {
180
+ method: "delete",
181
+ });
182
+ },
183
+ /**
184
+ * Get an Asana Workspace.
185
+ *
186
+ * @param {string} workspaceId - The workspace GID.
187
+ *
188
+ * @returns {string} An Asana Workspace.
189
+ */
190
+ async getWorkspace(workspaceId) {
191
+ return (await this._makeRequest(`workspaces/${workspaceId}`)).data;
192
+ },
193
+ /**
194
+ * Get an Asana Workspace list.
195
+ *
196
+ * @returns {string} An Asana Workspace object list.
197
+ */
198
+ async getWorkspaces() {
199
+ return (await this._makeRequest("workspaces")).data;
200
+ },
201
+ /**
202
+ * Get an Asana Organizations list.
203
+ *
204
+ * @returns {string} An Asana Organizations list.
205
+ */
206
+ async getOrganizations() {
207
+ const workspaces = await this.getWorkspaces();
208
+
209
+ const organizations = workspaces.filter(async (workspace) => {
210
+ workspace = await this.getWorkspace(workspace.gid);
211
+
212
+ return workspace.is_organization;
213
+ });
214
+
215
+ return organizations;
216
+ },
217
+ /**
218
+ * Get an Asana Project.
219
+ *
220
+ * @param {string} projectId - The project GID.
221
+ *
222
+ * @returns {string} An Asana Project.
223
+ */
224
+ async getProject(projectId) {
225
+ return (await this._makeRequest(`projects/${projectId}`)).data;
226
+ },
227
+ /**
228
+ * Get an Asana Project list.
229
+ *
230
+ * @param {string} workspaceId - The Workspace GID.
231
+ *
232
+ * @returns {string} An Asana Project list.
233
+ */
234
+ async getProjects(workspaceId, params = {}, $) {
235
+ return (await this._makeRequest("projects", {
236
+ params: {
237
+ workspace: workspaceId,
238
+ ...params,
239
+ },
240
+ }, $)).data;
241
+ },
242
+ /**
243
+ * Get an Asana Story.
244
+ *
245
+ * @param {string} storyId - The story GID.
246
+ *
247
+ * @returns {string} An Asana Story.
248
+ */
249
+ async getStory(storyId) {
250
+ return (await this._makeRequest(`stories/${storyId}`)).data;
251
+ },
252
+ /**
253
+ * Get an Asana Task.
254
+ *
255
+ * @param {string} taskId - The Task GID.
256
+ *
257
+ * @returns {string} An Asana Task.
258
+ */
259
+ async getTask(taskId, $) {
260
+ return (await this._makeRequest(`tasks/${taskId}`), {}, $).data;
261
+ },
262
+ /**
263
+ * Get an Asana Task list.
264
+ *
265
+ * @param {string} params - The params to filter tasks.
266
+ *
267
+ * @returns {string} An Asana Task list.
268
+ */
269
+ async getTasks(params, $) {
270
+ const response = await this._makeRequest("tasks", params, $);
271
+
272
+ return response.data;
273
+ },
274
+ /**
275
+ * Get an Asana Section list.
276
+ *
277
+ * @param {string} project - A Project GID.
278
+ *
279
+ * @returns {string} An Asana Section list.
280
+ */
281
+ async getSections(project, $) {
282
+ const response = await this._makeRequest(`projects/${project}/sections`, {}, $);
283
+
284
+ return response.data ?? [];
285
+ },
286
+ /**
287
+ * Get an Asana Tag.
288
+ *
289
+ * @param {string} tagId - A Tag GID.
290
+ *
291
+ * @returns {string} An Asana Tag.
292
+ */
293
+ async getTag(tagId) {
294
+ return (await this._makeRequest(`tags/${tagId}`)).data;
295
+ },
296
+ /**
297
+ * Get an Asana Tag list.
298
+ *
299
+ * @returns {string} An Asana Tag list.
300
+ */
301
+ async getTags() {
302
+ return (await this._makeRequest("tags")).data;
303
+ },
304
+ /**
305
+ * Get an Asana Team.
306
+ *
307
+ * @param {string} teamId - A Team GID.
308
+ *
309
+ * @returns {string} An Asana Team.
310
+ */
311
+ async getTeam(teamId) {
312
+ return (await this._makeRequest(`teams/${teamId}`)).data;
313
+ },
314
+ /**
315
+ * Get an Asana Team list.
316
+ *
317
+ * @param {string} workspaces - A Workspace GID list.
318
+ *
319
+ * @returns {string} An Asana Team list.
320
+ */
321
+ async getTeams(workspaces) {
322
+ if (!Array.isArray(workspaces)) workspaces = [
323
+ workspaces,
324
+ ];
325
+
326
+ let teams = [];
327
+
328
+ for (const workspace of workspaces) {
329
+ const response = (await this._makeRequest(`organizations/${workspace}/teams`));
330
+
331
+ teams = teams.concat(response.data);
332
+ }
333
+
334
+ return teams;
335
+ },
336
+ /**
337
+ * Get an Asana Workspace Membership.
338
+ *
339
+ * @param {string} membership - A Workspace Membership GID.
340
+ *
341
+ * @returns {string} A Workspace Membership.
342
+ */
343
+ async getWorkspaceMembership(membership) {
344
+ return (await this._makeRequest(`workspace_memberships/${membership}`)).data;
345
+ },
346
+ /**
347
+ * Get an Asana User.
348
+ *
349
+ * @param {string} userId - An User GID.
350
+ *
351
+ * @returns {string} An Asana User.
352
+ */
353
+ async getUser(userId) {
354
+ return (await this._makeRequest(`users/${userId}`)).data;
355
+ },
356
+ /**
357
+ * Get an Asana User list.
358
+ *
359
+ * @param {string} params - The params to filter the users.
360
+ *
361
+ * @returns {string} An Asana User list.
362
+ */
363
+ async getUsers(params = {}) {
364
+ const {
365
+ workspace,
366
+ team,
367
+ } = params;
368
+
369
+ return (await this._makeRequest("users", {
370
+ params: {
371
+ workspace,
372
+ team,
373
+ },
374
+ })).data;
375
+ },
376
+ },
377
+ };