@pipedream/asana 0.6.0 → 0.6.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.
Files changed (31) hide show
  1. package/actions/add-task-to-section/add-task-to-section.mjs +6 -4
  2. package/actions/common/common.mjs +3 -0
  3. package/actions/create-project/create-project.mjs +6 -4
  4. package/actions/create-subtask/create-subtask.mjs +6 -4
  5. package/actions/create-task/create-task.mjs +6 -4
  6. package/actions/create-task-comment/create-task-comment.mjs +6 -4
  7. package/actions/delete-task/delete-task.mjs +6 -4
  8. package/actions/find-task-by-id/find-task-by-id.mjs +6 -3
  9. package/actions/get-tasks-from-task-list/get-tasks-from-task-list.mjs +9 -7
  10. package/actions/search-projects/search-projects.mjs +9 -5
  11. package/actions/search-sections/search-sections.mjs +6 -3
  12. package/actions/search-tasks/search-tasks.mjs +6 -5
  13. package/actions/search-user-projects/search-user-projects.mjs +13 -5
  14. package/actions/update-task/update-task.mjs +7 -5
  15. package/asana.app.mjs +288 -146
  16. package/package.json +3 -2
  17. package/sources/common/common.mjs +5 -3
  18. package/sources/new-completed-task/new-completed-task.mjs +4 -2
  19. package/sources/new-project/new-project.mjs +4 -2
  20. package/sources/new-story/new-story.mjs +4 -2
  21. package/sources/new-subtask/new-subtask.mjs +4 -2
  22. package/sources/new-tag/new-tag.mjs +6 -4
  23. package/sources/new-task/new-task.mjs +8 -3
  24. package/sources/new-team/new-team.mjs +5 -3
  25. package/sources/new-user/new-user.mjs +7 -3
  26. package/sources/new-workspace/new-workspace.mjs +6 -5
  27. package/sources/tag-added-to-task/tag-added-to-task.mjs +7 -3
  28. package/sources/tags-added-to-any-task/tags-added-to-any-task.mjs +8 -7
  29. package/sources/task-assigned-in-project/task-assigned-in-project.mjs +5 -3
  30. package/sources/task-field-updated-in-project/task-field-updated-in-project.mjs +5 -3
  31. package/sources/task-updated-in-project/task-updated-in-project.mjs +4 -2
package/asana.app.mjs CHANGED
@@ -6,115 +6,207 @@ export default {
6
6
  propDefinitions: {
7
7
  organizations: {
8
8
  label: "Organizations",
9
- description: "List of organizations. This field use the organization GID.",
9
+ description: "List of organizations. This field uses the organization GID.",
10
10
  type: "string[]",
11
11
  async options() {
12
12
  const organizations = await this.getOrganizations();
13
-
14
- return organizations.map((organization) => ({
13
+ return organizations?.map((organization) => ({
15
14
  label: organization.name,
16
15
  value: organization.gid,
17
- }));
16
+ })) || [];
18
17
  },
19
18
  },
20
19
  workspaces: {
21
20
  label: "Workspaces",
22
- description: "List of workspaces. This field use the workspace GID.",
21
+ description: "List of workspaces. This field uses the workspace GID.",
23
22
  type: "string[]",
24
- async options() {
25
- const workspaces = await this.getWorkspaces();
26
-
27
- return workspaces.map((workspace) => ({
23
+ async options({ prevContext }) {
24
+ const params = prevContext?.offset
25
+ ? {
26
+ offset: prevContext.offset,
27
+ }
28
+ : {};
29
+ const {
30
+ data: workspaces, next_page: next,
31
+ } = await this.getWorkspaces({
32
+ params,
33
+ });
34
+ const options = workspaces?.map((workspace) => ({
28
35
  label: workspace.name,
29
36
  value: workspace.gid,
30
- }));
37
+ })) || [];
38
+ return {
39
+ options,
40
+ context: {
41
+ offset: next?.offset,
42
+ },
43
+ };
31
44
  },
32
45
  },
33
46
  teams: {
34
47
  label: "Teams",
35
- description: "List of teams. This field use the team GID.",
48
+ description: "List of teams. This field uses the team GID.",
36
49
  type: "string[]",
37
- async options() {
38
- const teams = await this.getTeams();
39
-
40
- return teams.map((team) => ({
50
+ async options({ workspaces }) {
51
+ const teams = await this.getTeams(workspaces);
52
+ return teams?.map((team) => ({
41
53
  label: team.name,
42
54
  value: team.gid,
43
- }));
55
+ })) || [];
44
56
  },
45
57
  },
46
58
  projects: {
47
59
  label: "Projects",
48
- description: "List of projects. This field use the project GID.",
60
+ description: "List of projects. This field uses the project GID.",
49
61
  type: "string[]",
50
- async options({ workspace }) {
51
- const projects = await this.getProjects(workspace);
52
-
53
- return projects.map((tag) => ({
62
+ async options({
63
+ workspace, prevContext,
64
+ }) {
65
+ const params = workspace
66
+ ? {
67
+ workspace,
68
+ }
69
+ : {};
70
+ if (prevContext?.offset) {
71
+ params.offset = prevContext.offset;
72
+ }
73
+ const {
74
+ data: projects, next_page: next,
75
+ } = await this.getProjects({
76
+ params,
77
+ });
78
+ const options = projects?.map((tag) => ({
54
79
  label: tag.name,
55
80
  value: tag.gid,
56
- }));
81
+ })) || [];
82
+ return {
83
+ options,
84
+ context: {
85
+ offset: next?.offset,
86
+ },
87
+ };
57
88
  },
58
89
  },
59
90
  tags: {
60
91
  label: "Tags",
61
- description: "List of tags. This field use the tag GID.",
92
+ description: "List of tags. This field uses the tag GID.",
62
93
  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
- };
94
+ async options({ prevContext }) {
95
+ const params = prevContext?.offset
96
+ ? {
97
+ offset: prevContext.offset,
98
+ }
99
+ : {};
100
+ const {
101
+ data: tags, next_page: next,
102
+ } = await this.getTags({
103
+ params,
71
104
  });
105
+ const options = tags?.map((tag) => ({
106
+ label: tag.name,
107
+ value: tag.gid,
108
+ })) || [];
109
+ return {
110
+ options,
111
+ context: {
112
+ offset: next?.offset,
113
+ },
114
+ };
72
115
  },
73
116
  },
74
117
  users: {
75
118
  label: "Users",
76
- description: "List of users. This field use the user GID.",
119
+ description: "List of users. This field uses the user GID.",
77
120
  type: "string[]",
78
- async options() {
79
- const users = await this.getUsers();
80
-
81
- return users.map((user) => ({
121
+ async options({ prevContext }) {
122
+ const params = prevContext?.offset
123
+ ? {
124
+ offset: prevContext.offset,
125
+ }
126
+ : {};
127
+ const {
128
+ data: users, next_page: next,
129
+ } = await this.getUsers({
130
+ params,
131
+ });
132
+ const options = users?.map((user) => ({
82
133
  label: user.name,
83
134
  value: user.gid,
84
- }));
135
+ })) || [];
136
+ return {
137
+ options,
138
+ context: {
139
+ offset: next?.offset,
140
+ },
141
+ };
85
142
  },
86
143
  },
87
144
  tasks: {
88
145
  label: "Tasks",
89
- description: "List of tasks. This field use the task GID.",
146
+ description: "List of tasks. This field uses the task GID.",
90
147
  type: "string[]",
91
- async options({ project }) {
92
- const tasks = await this.getTasks({
93
- params: {
94
- project,
95
- },
148
+ async options({
149
+ project, prevContext,
150
+ }) {
151
+ if (!project) {
152
+ return [];
153
+ }
154
+ const params = {
155
+ project,
156
+ };
157
+ if (prevContext?.offset) {
158
+ params.offset = prevContext.offset;
159
+ }
160
+ const {
161
+ data: tasks, next_page: next,
162
+ } = await this.getTasks({
163
+ params,
96
164
  });
97
- return tasks.map(({
165
+ const options = tasks?.map(({
98
166
  name: label, gid: value,
99
167
  }) => ({
100
168
  label,
101
169
  value,
102
- }));
170
+ })) || [];
171
+ return {
172
+ options,
173
+ context: {
174
+ offset: next?.offset,
175
+ },
176
+ };
103
177
  },
104
178
  },
105
179
  sections: {
106
180
  label: "Sections",
107
- description: "List of sections. This field use the section GID.",
181
+ description: "List of sections. This field uses the section GID.",
108
182
  type: "string[]",
109
- async options({ project }) {
110
- const sections = await this.getSections(project);
111
-
112
- return sections.map((section) => {
113
- return {
114
- label: section.name,
115
- value: section.gid,
116
- };
183
+ async options({
184
+ project, prevContext,
185
+ }) {
186
+ if (!project) {
187
+ return [];
188
+ }
189
+ const params = prevContext?.offset
190
+ ? {
191
+ offset: prevContext.offset,
192
+ }
193
+ : {};
194
+ const {
195
+ data: sections, next_page: next,
196
+ } = await this.getSections({
197
+ project,
198
+ params,
117
199
  });
200
+ const options = sections?.map((section) => ({
201
+ label: section.name,
202
+ value: section.gid,
203
+ })) || [];
204
+ return {
205
+ options,
206
+ context: {
207
+ offset: next?.offset,
208
+ },
209
+ };
118
210
  },
119
211
  },
120
212
  taskFields: {
@@ -128,12 +220,10 @@ export default {
128
220
  limit: 1,
129
221
  },
130
222
  });
131
-
132
223
  if (!tasks || tasks.length === 0) {
133
224
  return [];
134
225
  }
135
226
  const task = await this.getTask(tasks[0].gid);
136
-
137
227
  return Object.keys(task);
138
228
  },
139
229
  },
@@ -165,32 +255,33 @@ export default {
165
255
  * Make a requests with pre defined options.
166
256
  *
167
257
  * @param {string} path - The path to make the request.
168
- * @param {object} options - A default Axios options object.
258
+ * @param {object} opts - A default Axios options object.
169
259
  *
170
260
  * @returns {string} The request result data.
171
261
  */
172
- async _makeRequest(path, options = {}, $ = this) {
262
+ _makeRequest({
263
+ path, $ = this, ...opts
264
+ }) {
173
265
  const config = {
174
266
  url: `${this._apiUrl()}/${path}`,
175
267
  headers: this._headers(),
176
- ...options,
268
+ ...opts,
177
269
  };
178
270
  return axios($, config);
179
271
  },
180
272
  /**
181
273
  * Create a webhook
182
274
  *
183
- * @param {string} body - The body that will be send on request.
275
+ * @param {string} opts.data - The body that will be send on request.
184
276
  *
185
- * @returns {object} A Asana Webhook.
277
+ * @returns {object} An Asana Webhook.
186
278
  */
187
- async createWebHook(body) {
188
- const authorization = await this._makeRequest("webhooks", {
279
+ async createWebHook(opts = {}) {
280
+ return this._makeRequest({
281
+ path: "webhooks",
189
282
  method: "post",
190
- data: body,
283
+ ...opts,
191
284
  });
192
-
193
- return authorization.data;
194
285
  },
195
286
  /**
196
287
  * Remove a Webhook.
@@ -198,7 +289,8 @@ export default {
198
289
  * @param {string} hookId - The Asana Webhook GID.
199
290
  */
200
291
  async deleteWebhook(hookId) {
201
- await this._makeRequest(`webhooks/${hookId}`, {
292
+ await this._makeRequest({
293
+ path: `webhooks/${hookId}`,
202
294
  method: "delete",
203
295
  });
204
296
  },
@@ -209,16 +301,24 @@ export default {
209
301
  *
210
302
  * @returns {string} An Asana Workspace.
211
303
  */
212
- async getWorkspace(workspaceId) {
213
- return (await this._makeRequest(`workspaces/${workspaceId}`)).data;
304
+ getWorkspace({
305
+ workspaceId, ...opts
306
+ }) {
307
+ return this._makeRequest({
308
+ path: `workspaces/${workspaceId}`,
309
+ ...opts,
310
+ });
214
311
  },
215
312
  /**
216
313
  * Get an Asana Workspace list.
217
314
  *
218
315
  * @returns {string} An Asana Workspace object list.
219
316
  */
220
- async getWorkspaces() {
221
- return (await this._makeRequest("workspaces")).data;
317
+ getWorkspaces(opts = {}) {
318
+ return this._makeRequest({
319
+ path: "workspaces",
320
+ ...opts,
321
+ });
222
322
  },
223
323
  /**
224
324
  * Get an Asana Organizations list.
@@ -226,14 +326,24 @@ export default {
226
326
  * @returns {string} An Asana Organizations list.
227
327
  */
228
328
  async getOrganizations() {
229
- const workspaces = await this.getWorkspaces();
329
+ const params = {};
330
+ const workspaces = [];
331
+ do {
332
+ const {
333
+ data, next_page: next,
334
+ } = await this.getWorkspaces({
335
+ params,
336
+ });
337
+ workspaces.push(...data);
338
+ params.offset = next?.offset;
339
+ } while (params.offset);
230
340
 
231
341
  const organizations = workspaces.filter(async (workspace) => {
232
- workspace = await this.getWorkspace(workspace.gid);
233
-
234
- return workspace.is_organization;
342
+ const { data } = await this.getWorkspace({
343
+ workspaceId: workspace.gid,
344
+ });
345
+ return data?.is_organization;
235
346
  });
236
-
237
347
  return organizations;
238
348
  },
239
349
  /**
@@ -243,23 +353,24 @@ export default {
243
353
  *
244
354
  * @returns {string} An Asana Project.
245
355
  */
246
- async getProject(projectId) {
247
- return (await this._makeRequest(`projects/${projectId}`)).data;
356
+ getProject({
357
+ projectId, ...opts
358
+ }) {
359
+ return this._makeRequest({
360
+ path: `projects/${projectId}`,
361
+ ...opts,
362
+ });
248
363
  },
249
364
  /**
250
365
  * Get an Asana Project list.
251
366
  *
252
- * @param {string} workspaceId - The Workspace GID.
253
- *
254
367
  * @returns {string} An Asana Project list.
255
368
  */
256
- async getProjects(workspaceId, params = {}, $) {
257
- return (await this._makeRequest("projects", {
258
- params: {
259
- workspace: workspaceId,
260
- ...params,
261
- },
262
- }, $)).data;
369
+ getProjects(opts = {}) {
370
+ return this._makeRequest({
371
+ path: "projects",
372
+ ...opts,
373
+ });
263
374
  },
264
375
  /**
265
376
  * Get an Asana Story.
@@ -268,8 +379,13 @@ export default {
268
379
  *
269
380
  * @returns {string} An Asana Story.
270
381
  */
271
- async getStory(storyId) {
272
- return (await this._makeRequest(`stories/${storyId}`)).data;
382
+ getStory({
383
+ storyId, ...opts
384
+ }) {
385
+ return this._makeRequest({
386
+ path: `stories/${storyId}`,
387
+ ...opts,
388
+ });
273
389
  },
274
390
  /**
275
391
  * Get an Asana Task.
@@ -278,33 +394,41 @@ export default {
278
394
  *
279
395
  * @returns {string} An Asana Task.
280
396
  */
281
- async getTask(taskId, $) {
282
- const response = await this._makeRequest(`tasks/${taskId}`, {}, $);
283
- return response.data;
397
+ getTask({
398
+ taskId, ...opts
399
+ }) {
400
+ return this._makeRequest({
401
+ path: `tasks/${taskId}`,
402
+ ...opts,
403
+ });
284
404
  },
285
405
  /**
286
406
  * Get an Asana Task list.
287
407
  *
288
- * @param {string} params - The params to filter tasks.
408
+ * @param {string} opts - The params to filter tasks.
289
409
  *
290
410
  * @returns {string} An Asana Task list.
291
411
  */
292
- async getTasks(params, $) {
293
- const response = await this._makeRequest("tasks", params, $);
294
-
295
- return response.data;
412
+ getTasks(opts = {}) {
413
+ return this._makeRequest({
414
+ path: "tasks",
415
+ ...opts,
416
+ });
296
417
  },
297
418
  /**
298
419
  * Get an Asana Section list.
299
420
  *
300
- * @param {string} project - A Project GID.
421
+ * @param {string} projectId - A Project GID.
301
422
  *
302
423
  * @returns {string} An Asana Section list.
303
424
  */
304
- async getSections(project, $) {
305
- const response = await this._makeRequest(`projects/${project}/sections`, {}, $);
306
-
307
- return response.data ?? [];
425
+ getSections({
426
+ project, ...opts
427
+ }) {
428
+ return this._makeRequest({
429
+ path: `projects/${project}/sections`,
430
+ ...opts,
431
+ });
308
432
  },
309
433
  /**
310
434
  * Get an Asana Tag.
@@ -313,16 +437,24 @@ export default {
313
437
  *
314
438
  * @returns {string} An Asana Tag.
315
439
  */
316
- async getTag(tagId) {
317
- return (await this._makeRequest(`tags/${tagId}`)).data;
440
+ getTag({
441
+ tagId, ...opts
442
+ }) {
443
+ return this._makeRequest({
444
+ path: `tags/${tagId}`,
445
+ opts,
446
+ });
318
447
  },
319
448
  /**
320
449
  * Get an Asana Tag list.
321
450
  *
322
451
  * @returns {string} An Asana Tag list.
323
452
  */
324
- async getTags() {
325
- return (await this._makeRequest("tags")).data;
453
+ getTags(opts = {}) {
454
+ return this._makeRequest({
455
+ path: "tags",
456
+ ...opts,
457
+ });
326
458
  },
327
459
  /**
328
460
  * Get an Asana Team.
@@ -331,8 +463,13 @@ export default {
331
463
  *
332
464
  * @returns {string} An Asana Team.
333
465
  */
334
- async getTeam(teamId) {
335
- return (await this._makeRequest(`teams/${teamId}`)).data;
466
+ getTeam({
467
+ teamId, ...opts
468
+ }) {
469
+ return this._makeRequest({
470
+ path: `teams/${teamId}`,
471
+ ...opts,
472
+ });
336
473
  },
337
474
  /**
338
475
  * Get an Asana Team list.
@@ -349,9 +486,8 @@ export default {
349
486
  let teams = [];
350
487
 
351
488
  for (const workspace of workspaces) {
352
- const response = (await this._makeRequest(`organizations/${workspace}/teams`));
353
-
354
- teams = teams.concat(response.data);
489
+ const { data } = (await this._makeRequest(`organizations/${workspace}/teams`));
490
+ teams = teams.concat(data);
355
491
  }
356
492
 
357
493
  return teams;
@@ -359,12 +495,17 @@ export default {
359
495
  /**
360
496
  * Get an Asana Workspace Membership.
361
497
  *
362
- * @param {string} membership - A Workspace Membership GID.
498
+ * @param {string} membershipId - A Workspace Membership GID.
363
499
  *
364
500
  * @returns {string} A Workspace Membership.
365
501
  */
366
- async getWorkspaceMembership(membership) {
367
- return (await this._makeRequest(`workspace_memberships/${membership}`)).data;
502
+ getWorkspaceMembership({
503
+ membershipId, ...opts
504
+ }) {
505
+ return this._makeRequest({
506
+ path: `workspace_memberships/${membershipId}`,
507
+ ...opts,
508
+ });
368
509
  },
369
510
  /**
370
511
  * Get an Asana User.
@@ -373,46 +514,47 @@ export default {
373
514
  *
374
515
  * @returns {string} An Asana User.
375
516
  */
376
- async getUser(userId) {
377
- return (await this._makeRequest(`users/${userId}`)).data;
517
+ getUser({
518
+ userId, ...opts
519
+ }) {
520
+ return this._makeRequest({
521
+ path: `users/${userId}`,
522
+ ...opts,
523
+ });
378
524
  },
379
525
  /**
380
526
  * Get an Asana User list.
381
527
  *
382
- * @param {string} params - The params to filter the users.
528
+ * @param {string} opts.params - The params to filter the users.
383
529
  *
384
530
  * @returns {string} An Asana User list.
385
531
  */
386
- async getUsers(params = {}) {
387
- const {
388
- workspace,
389
- team,
390
- } = params;
391
-
392
- return (await this._makeRequest("users", {
393
- params: {
394
- workspace,
395
- team,
396
- },
397
- })).data;
398
- },
399
- async getUserTaskList(params, $) {
400
- const { userId } = params;
401
-
402
- return (await this._makeRequest(`users/${userId}/user_task_list`, {
403
- params: {
404
- workspace: params.workspace,
405
- project: params.project,
406
- },
407
- }, $)).data;
408
- },
409
- async getTasksFromUserTaskList(params, $) {
410
- const taskList = await this.getUserTaskList({
411
- ...params,
532
+ getUsers(opts = {}) {
533
+ return this._makeRequest({
534
+ path: "users",
535
+ ...opts,
536
+ });
537
+ },
538
+ getUserTaskList({
539
+ userId, ...opts
540
+ }) {
541
+ return this._makeRequest({
542
+ path: `users/${userId}/user_task_list`,
543
+ ...opts,
544
+ });
545
+ },
546
+ async getTasksFromUserTaskList({
547
+ params, $,
548
+ }) {
549
+ const { data: taskList } = await this.getUserTaskList({
412
550
  userId: "me",
413
- }, $);
414
-
415
- return (await this._makeRequest(`user_task_lists/${taskList.gid}/tasks`, {}, $)).data;
551
+ params,
552
+ $,
553
+ });
554
+ return this._makeRequest({
555
+ path: `user_task_lists/${taskList.gid}/tasks`,
556
+ $,
557
+ });
416
558
  },
417
559
  },
418
560
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/asana",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Pipedream Asana Components",
5
5
  "main": "asana.app.mjs",
6
6
  "keywords": [
@@ -11,7 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "dependencies": {
13
13
  "@pipedream/platform": "^1.2.0",
14
- "axios": "^0.21.1"
14
+ "axios": "^0.21.1",
15
+ "lodash": "^4.17.21"
15
16
  },
16
17
  "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
17
18
  "publishConfig": {
@@ -43,10 +43,12 @@ export default {
43
43
  },
44
44
  hooks: {
45
45
  async activate() {
46
- const response = await this.asana.createWebHook({
46
+ const { data: response } = await this.asana.createWebHook({
47
47
  data: {
48
- ...this.getWebhookFilter(),
49
- target: this.http.endpoint,
48
+ data: {
49
+ ...this.getWebhookFilter(),
50
+ target: this.http.endpoint,
51
+ },
50
52
  },
51
53
  });
52
54