@pipedream/asana 0.6.0 → 0.6.2

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