@pipedream/linear_app 0.4.1 → 0.4.3

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.
@@ -5,7 +5,7 @@ export default {
5
5
  key: "linear_app-create-issue",
6
6
  name: "Create Issue",
7
7
  description: "Create an issue (API Key). See the docs [here](https://developers.linear.app/docs/graphql/working-with-the-graphql-api#creating-and-editing-issues)",
8
- version: "0.3.5",
8
+ version: "0.3.6",
9
9
  props: {
10
10
  linearApp,
11
11
  teamId: {
@@ -4,7 +4,7 @@ export default {
4
4
  key: "linear_app-get-issue",
5
5
  name: "Get Issue",
6
6
  description: "Get an issue by ID (API Key). See the docs [here](https://developers.linear.app/docs/graphql/working-with-the-graphql-api)",
7
- version: "0.0.2",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  linearApp,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "linear_app-get-teams",
5
5
  name: "Get Teams",
6
6
  description: "Get all the teams (API Key). See the docs [here](https://developers.linear.app/docs/graphql/working-with-the-graphql-api)",
7
- version: "0.1.4",
7
+ version: "0.1.5",
8
8
  type: "action",
9
9
  props: {
10
10
  linearApp,
@@ -6,7 +6,7 @@ export default {
6
6
  name: "Search Issues",
7
7
  description: "Search issues (API Key). See the docs [here](https://developers.linear.app/docs/graphql/working-with-the-graphql-api)",
8
8
  type: "action",
9
- version: "0.1.3",
9
+ version: "0.1.4",
10
10
  props: {
11
11
  linearApp,
12
12
  query: {
@@ -5,7 +5,7 @@ export default {
5
5
  name: "Update Issue",
6
6
  description: "Update an issue (API Key). See the docs [here](https://developers.linear.app/docs/graphql/working-with-the-graphql-api#creating-and-editing-issues)",
7
7
  type: "action",
8
- version: "0.0.4",
8
+ version: "0.0.5",
9
9
  props: {
10
10
  linearApp,
11
11
  issueId: {
@@ -1,6 +1,7 @@
1
1
  const WEBHOOK_ID = "webhookId";
2
2
  const LINEAR_DELIVERY_HEADER = "linear-delivery";
3
- const DEFAULT_LIMIT = 50;
3
+ const DEFAULT_LIMIT = 100;
4
+ const DEFAULT_MAX_RECORDS = 200;
4
5
 
5
6
  const ACTION = {
6
7
  CREATE: "create",
@@ -46,6 +47,7 @@ export default {
46
47
  WEBHOOK_ID,
47
48
  LINEAR_DELIVERY_HEADER,
48
49
  DEFAULT_LIMIT,
50
+ DEFAULT_MAX_RECORDS,
49
51
  ACTION,
50
52
  RESOURCE_TYPE,
51
53
  RESOURCE_TYPES,
@@ -0,0 +1,11 @@
1
+ async function streamIterator(stream) {
2
+ const resources = [];
3
+ for await (const resource of stream) {
4
+ resources.push(resource);
5
+ }
6
+ return resources;
7
+ }
8
+
9
+ export default {
10
+ streamIterator,
11
+ };
@@ -203,42 +203,31 @@ export default {
203
203
  },
204
204
  };
205
205
  },
206
- async *paginateResources({ resourcesFn }) {
207
- const params = {
208
- after: null,
209
- first: constants.DEFAULT_LIMIT,
210
- };
211
- let hasNextPage = true;
206
+ async *paginateResources({
207
+ resourcesFn,
208
+ resourcesFnArgs,
209
+ max = constants.DEFAULT_MAX_RECORDS,
210
+ }) {
211
+ let counter = 0;
212
+ let hasNextPage;
213
+ let endCursor;
212
214
  do {
213
215
  const {
214
216
  nodes,
215
217
  pageInfo,
216
- } = await resourcesFn(params);
217
- for (const d of nodes) {
218
- yield d;
219
- }
220
- hasNextPage = pageInfo.hasNextPage;
221
- if (hasNextPage) {
222
- params.after = pageInfo.endCursor;
223
- }
224
- } while (hasNextPage);
225
- },
226
- isActionSet(body, actions) {
227
- if (!actions.includes(body?.action)) {
228
- return false;
229
- }
230
- return true;
231
- },
232
- async isProjectIdSet(body, projectId) {
233
- if (projectId) {
234
- if (!body.data?.projectId) {
235
- const issue = body.data?.issue?.id && await this.getIssue(body.data?.issue?.id);
236
- return issue?._project?.id === projectId;
237
- } else {
238
- return body.data.projectId === projectId;
218
+ } = await resourcesFn({
219
+ after: endCursor,
220
+ first: constants.DEFAULT_LIMIT,
221
+ ...resourcesFnArgs,
222
+ });
223
+ for (const node of nodes) {
224
+ counter += 1;
225
+ yield node;
239
226
  }
240
- }
241
- return true;
227
+ ({
228
+ hasNextPage, endCursor,
229
+ } = pageInfo);
230
+ } while (hasNextPage && counter < max);
242
231
  },
243
232
  },
244
233
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/linear_app",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Pipedream Linear_app Components",
5
5
  "main": "linear_app.app.mjs",
6
6
  "keywords": [
@@ -7,7 +7,7 @@ export default {
7
7
  name: "New Created Comment (Instant)",
8
8
  description: "Emit new event when a new comment is created. See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
9
9
  type: "source",
10
- version: "0.0.3",
10
+ version: "0.0.5",
11
11
  dedupe: "unique",
12
12
  methods: {
13
13
  ...common.methods,
@@ -19,27 +19,38 @@ export default {
19
19
  getWebhookLabel() {
20
20
  return "Comment created";
21
21
  },
22
- getActions() {
23
- return [
24
- constants.ACTION.CREATE,
25
- ];
26
- },
27
22
  getResourcesFn() {
28
23
  return this.linearApp.listComments;
29
24
  },
30
- async getLoadedProjectId(event) {
31
- return event?._project?.id
32
- || (await this.linearApp.getIssue(event?._issue?.id))?._project?.id;
25
+ getResourcesFnArgs() {
26
+ return {
27
+ sortBy: "createdAt",
28
+ filter: {
29
+ issue: {
30
+ team: {
31
+ id: {
32
+ in: this.teamIds,
33
+ },
34
+ },
35
+ project: {
36
+ id: {
37
+ eq: this.projectId,
38
+ },
39
+ },
40
+ },
41
+ },
42
+ };
33
43
  },
34
44
  getMetadata(resource) {
35
45
  const {
36
46
  delivery,
47
+ body,
37
48
  data,
38
49
  createdAt,
39
50
  } = resource;
40
51
  return {
41
- id: delivery,
42
- summary: `New comment event created: ${data.body}`,
52
+ id: delivery || resource.id,
53
+ summary: `New comment event created: ${data?.body || body}`,
43
54
  ts: Date.parse(createdAt),
44
55
  };
45
56
  },
@@ -1,5 +1,6 @@
1
1
  import linearApp from "../../linear_app.app.mjs";
2
2
  import constants from "../../common/constants.mjs";
3
+ import utils from "../../common/utils.mjs";
3
4
 
4
5
  export default {
5
6
  props: {
@@ -11,7 +12,12 @@ export default {
11
12
  linearApp,
12
13
  "teamId",
13
14
  ],
14
- optional: true,
15
+ },
16
+ projectId: {
17
+ propDefinition: [
18
+ linearApp,
19
+ "projectId",
20
+ ],
15
21
  },
16
22
  http: "$.interface.http",
17
23
  db: "$.service.db",
@@ -32,15 +38,15 @@ export default {
32
38
  getWebhookLabel() {
33
39
  throw new Error("getWebhookLabel is not implemented");
34
40
  },
35
- getActions() {
36
- throw new Error("getActions is not implemented");
37
- },
38
41
  getMetadata() {
39
42
  throw new Error("getMetadata is not implemented");
40
43
  },
41
44
  getResourcesFn() {
42
45
  throw new Error("Get resource function not implemented");
43
46
  },
47
+ getResourcesFnArgs() {
48
+ throw new Error("Get resource function arguments not implemented");
49
+ },
44
50
  getLoadedProjectId() {
45
51
  throw new Error("Get loaded project ID not implemented");
46
52
  },
@@ -49,38 +55,27 @@ export default {
49
55
  async deploy() {
50
56
  // Retrieve historical events
51
57
  console.log("Retrieving historical events...");
52
- const events = this.linearApp.paginateResources({
58
+ const stream = this.linearApp.paginateResources({
53
59
  resourcesFn: this.getResourcesFn(),
60
+ resourcesFnArgs: this.getResourcesFnArgs(),
54
61
  });
55
- for await (const event of events) {
56
- const loadedProjectId = await this.getLoadedProjectId(event);
57
- if (this.projectId && loadedProjectId !== this.projectId) {
58
- continue;
59
- }
60
- event.projectId = loadedProjectId;
61
- const [
62
- action,
63
- ] = this.getActions();
64
- const [
65
- resourceType,
66
- ] = this.getResourceTypes();
67
- this.$emit(event, {
68
- id: event.id,
69
- ts: Date.parse(event.updatedAt),
70
- summary: `New ${action} ${resourceType} event: ${event.id}`,
62
+ const resources = await utils.streamIterator(stream);
63
+
64
+ resources
65
+ .reverse()
66
+ .forEach((resource) => {
67
+ this.$emit(resource, this.getMetadata(resource));
71
68
  });
72
- }
73
69
  },
74
70
  async activate() {
75
- const params = {
76
- resourceTypes: this.getResourceTypes(),
77
- url: this.http.endpoint,
78
- label: this.getWebhookLabel(),
79
- };
80
-
81
71
  for (const teamId of this.teamIds) {
82
- params.teamId = teamId;
83
- const { _webhook: webhook } = await this.linearApp.createWebhook(params);
72
+ const { _webhook: webhook } =
73
+ await this.linearApp.createWebhook({
74
+ teamId,
75
+ resourceTypes: this.getResourceTypes(),
76
+ url: this.http.endpoint,
77
+ label: this.getWebhookLabel(),
78
+ });
84
79
  this.setWebhookId(teamId, webhook.id);
85
80
  }
86
81
  },
@@ -7,7 +7,7 @@ export default {
7
7
  name: "New Created Issue (Instant)",
8
8
  description: "Emit new event when a new issue is created. See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
9
9
  type: "source",
10
- version: "0.2.2",
10
+ version: "0.2.4",
11
11
  dedupe: "unique",
12
12
  methods: {
13
13
  ...common.methods,
@@ -19,27 +19,36 @@ export default {
19
19
  getWebhookLabel() {
20
20
  return "Issue created";
21
21
  },
22
- getActions() {
23
- return [
24
- constants.ACTION.CREATE,
25
- ];
26
- },
27
22
  getResourcesFn() {
28
23
  return this.linearApp.listIssues;
29
24
  },
30
- async getLoadedProjectId(event) {
31
- return event?._project?.id
32
- || (await this.linearApp.getIssue(event?.id))?._project?.id;
25
+ getResourcesFnArgs() {
26
+ return {
27
+ sortBy: "createdAt",
28
+ filter: {
29
+ team: {
30
+ id: {
31
+ in: this.teamIds,
32
+ },
33
+ },
34
+ project: {
35
+ id: {
36
+ eq: this.projectId,
37
+ },
38
+ },
39
+ },
40
+ };
33
41
  },
34
42
  getMetadata(resource) {
35
43
  const {
36
44
  delivery,
45
+ title,
37
46
  data,
38
47
  createdAt,
39
48
  } = resource;
40
49
  return {
41
- id: delivery,
42
- summary: `Issue created: ${data.title}`,
50
+ id: delivery || resource.id,
51
+ summary: `Issue created: ${data?.title || title}`,
43
52
  ts: Date.parse(createdAt),
44
53
  };
45
54
  },
@@ -7,7 +7,7 @@ export default {
7
7
  name: "New Updated Issue (Instant)",
8
8
  description: "Emit new event when an issue is updated. See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
9
9
  type: "source",
10
- version: "0.2.2",
10
+ version: "0.2.4",
11
11
  dedupe: "unique",
12
12
  methods: {
13
13
  ...common.methods,
@@ -19,27 +19,36 @@ export default {
19
19
  getWebhookLabel() {
20
20
  return "Issue updated";
21
21
  },
22
- getActions() {
23
- return [
24
- constants.ACTION.UPDATE,
25
- ];
26
- },
27
22
  getResourcesFn() {
28
23
  return this.linearApp.listIssues;
29
24
  },
30
- async getLoadedProjectId(event) {
31
- return event?._project?.id
32
- || (await this.linearApp.getIssue(event?.id))?._project?.id;
25
+ getResourcesFnArgs() {
26
+ return {
27
+ sortBy: "updatedAt",
28
+ filter: {
29
+ team: {
30
+ id: {
31
+ in: this.teamIds,
32
+ },
33
+ },
34
+ project: {
35
+ id: {
36
+ eq: this.projectId,
37
+ },
38
+ },
39
+ },
40
+ };
33
41
  },
34
42
  getMetadata(resource) {
35
43
  const {
36
44
  delivery,
45
+ title,
37
46
  data,
38
47
  updatedAt,
39
48
  } = resource;
40
49
  return {
41
- id: delivery,
42
- summary: `Issue Updated: ${data.title}`,
50
+ id: delivery || resource.id,
51
+ summary: `Issue Updated: ${data?.title || title}`,
43
52
  ts: Date.parse(updatedAt),
44
53
  };
45
54
  },