@pipedream/topdesk 0.1.0 → 0.2.0

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.
@@ -4,7 +4,7 @@ export default {
4
4
  key: "topdesk-create-incident",
5
5
  name: "Create Incident",
6
6
  description: "Creates a new incident. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/createIncident)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  app,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "topdesk-get-incident",
5
5
  name: "Get Incident",
6
6
  description: "Returns an incident by ID. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/getIncidentById)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  app,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "topdesk-get-incidents",
5
5
  name: "Get Incidents",
6
6
  description: "Returns a list of incidents. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/getIncidents)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  app,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "topdesk-get-knowledge-item-statuses",
5
5
  name: "Get Knowledge Item Statuses",
6
6
  description: "Returns the list of possible Knowledge Item statuses. [See the documentation](https://developers.topdesk.com/explorer/?page=knowledge-base#/Searchlists/getStatuses)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  app,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "topdesk-get-knowledge-items",
5
5
  name: "Get Knowledge Items",
6
6
  description: "Returns a list of Knowledge Items. [See the documentation](https://developers.topdesk.com/explorer/?page=knowledge-base#/Knowledge%20Items/getKnowledgeItems)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  app,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "topdesk-update-incident",
5
5
  name: "Update Incident",
6
6
  description: "Updates an existing incident. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/patchIncident)",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  app,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/topdesk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream TOPdesk Components",
5
5
  "main": "topdesk.app.mjs",
6
6
  "keywords": [
@@ -13,6 +13,6 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@pipedream/platform": "^3.1.0"
16
+ "@pipedream/platform": "^3.1.1"
17
17
  }
18
18
  }
@@ -0,0 +1,99 @@
1
+ import topdesk from "../../topdesk.app.mjs";
2
+ import {
3
+ DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
4
+ } from "@pipedream/platform";
5
+
6
+ export default {
7
+ props: {
8
+ topdesk,
9
+ db: "$.service.db",
10
+ timer: {
11
+ type: "$.interface.timer",
12
+ default: {
13
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14
+ },
15
+ },
16
+ },
17
+ methods: {
18
+ _getLastTs() {
19
+ return this.db.get("lastTs") || 0;
20
+ },
21
+ _setLastTs(lastTs) {
22
+ this.db.set("lastTs", lastTs);
23
+ },
24
+ _getPreviousValue() {
25
+ return this.db.get("previousValue");
26
+ },
27
+ _setPreviousValue(previousValue) {
28
+ this.db.set("previousValue", previousValue);
29
+ },
30
+ getArgs() {
31
+ return {};
32
+ },
33
+ getTsField() {
34
+ return "modificationDate";
35
+ },
36
+ paginateResults() {
37
+ return false;
38
+ },
39
+ isRelevant() {
40
+ return true;
41
+ },
42
+ async getPaginatedResources(opts = {}) {
43
+ const results = this.topdesk.paginate(opts);
44
+ const items = [];
45
+ for await (const result of results) {
46
+ items.push(result);
47
+ }
48
+ return items;
49
+ },
50
+ async processEvents(max) {
51
+ const lastTs = this._getLastTs();
52
+ let maxTs = lastTs;
53
+
54
+ const resourceFn = this.getResourceFn();
55
+ const args = this.getArgs();
56
+ const tsField = this.getTsField();
57
+
58
+ const results = this.paginateResults()
59
+ ? await this.getPaginatedResources({
60
+ fn: resourceFn,
61
+ fnArgs: args,
62
+ maxResults: max,
63
+ })
64
+ : [
65
+ await resourceFn(args),
66
+ ];
67
+
68
+ if (!results.length) {
69
+ return;
70
+ }
71
+
72
+ for (const result of results.reverse()) {
73
+ const ts = Date.parse(result[tsField]);
74
+ if (ts >= lastTs) {
75
+ maxTs = Math.max(ts, maxTs);
76
+ if (this.isRelevant(result)) {
77
+ this.$emit(result, this.generateMeta(result));
78
+ }
79
+ }
80
+ }
81
+
82
+ this._setLastTs(maxTs);
83
+ },
84
+ getResourceFn() {
85
+ throw new ConfigurationError("getResourceFn must be implemented");
86
+ },
87
+ generateMeta() {
88
+ throw new ConfigurationError("generateMeta must be implemented");
89
+ },
90
+ },
91
+ hooks: {
92
+ async deploy() {
93
+ await this.processEvents(10);
94
+ },
95
+ },
96
+ async run() {
97
+ await this.processEvents();
98
+ },
99
+ };
@@ -0,0 +1,28 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-incident-updated",
6
+ name: "Incident Updated",
7
+ description: "Emit new event when an incident is updated. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/get_incidents)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ getResourceFn() {
14
+ return this.topdesk.listIncidents;
15
+ },
16
+ paginateResults() {
17
+ return true;
18
+ },
19
+ generateMeta(incident) {
20
+ const ts = Date.parse(incident.modificationDate);
21
+ return {
22
+ id: `${incident.id}-${ts}`,
23
+ summary: `Incident Updated: ${incident.id}`,
24
+ ts,
25
+ };
26
+ },
27
+ },
28
+ };
@@ -0,0 +1,52 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-new-incident-assignee",
6
+ name: "New Incident Assignee",
7
+ description: "Emit new event when an incident is assigned to a new user. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/get_incidents_id__id_)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ incidentId: {
14
+ propDefinition: [
15
+ common.props.topdesk,
16
+ "incidentId",
17
+ ],
18
+ },
19
+ },
20
+ methods: {
21
+ ...common.methods,
22
+ getResourceFn() {
23
+ return this.topdesk.getIncident;
24
+ },
25
+ getArgs() {
26
+ return {
27
+ incidentId: this.incidentId,
28
+ };
29
+ },
30
+ getTsField() {
31
+ return "modificationDate";
32
+ },
33
+ paginateResults() {
34
+ return false;
35
+ },
36
+ isRelevant(incident) {
37
+ const previousValue = this._getPreviousValue();
38
+ if (incident.operator?.id !== previousValue) {
39
+ this._setPreviousValue(incident.operator?.id);
40
+ return true;
41
+ }
42
+ return false;
43
+ },
44
+ generateMeta(incident) {
45
+ return {
46
+ id: incident.id,
47
+ summary: `New Incident Assignee: ${incident.operator?.name || `ID: ${incident.operator?.id}`}`,
48
+ ts: Date.parse(incident.modificationDate),
49
+ };
50
+ },
51
+ },
52
+ };
@@ -0,0 +1,30 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-new-incident-created",
6
+ name: "New Incident Created",
7
+ description: "Emit new event when a new incident is created. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/get_incidents)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ getResourceFn() {
14
+ return this.topdesk.listIncidents;
15
+ },
16
+ getTsField() {
17
+ return "creationDate";
18
+ },
19
+ paginateResults() {
20
+ return true;
21
+ },
22
+ generateMeta(incident) {
23
+ return {
24
+ id: incident.id,
25
+ summary: `New Incident: ${incident.id}`,
26
+ ts: Date.parse(incident.creationDate),
27
+ };
28
+ },
29
+ },
30
+ };
@@ -0,0 +1,52 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-new-incident-group-assigned",
6
+ name: "New Incident Group Assigned",
7
+ description: "Emit new event when an incident is assigned to a new group. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/get_incidents_id__id_)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ incidentId: {
14
+ propDefinition: [
15
+ common.props.topdesk,
16
+ "incidentId",
17
+ ],
18
+ },
19
+ },
20
+ methods: {
21
+ ...common.methods,
22
+ getResourceFn() {
23
+ return this.topdesk.getIncident;
24
+ },
25
+ getArgs() {
26
+ return {
27
+ incidentId: this.incidentId,
28
+ };
29
+ },
30
+ getTsField() {
31
+ return "modificationDate";
32
+ },
33
+ paginateResults() {
34
+ return false;
35
+ },
36
+ isRelevant(incident) {
37
+ const previousValue = this._getPreviousValue();
38
+ if (incident.caller.department?.id !== previousValue) {
39
+ this._setPreviousValue(incident.caller.department?.id);
40
+ return true;
41
+ }
42
+ return false;
43
+ },
44
+ generateMeta(incident) {
45
+ return {
46
+ id: incident.id,
47
+ summary: `New Incident Group Assigned: ${incident.caller.department?.name || `ID: ${incident.caller.department?.id}`}`,
48
+ ts: Date.parse(incident.modificationDate),
49
+ };
50
+ },
51
+ },
52
+ };
@@ -0,0 +1,52 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-new-incident-memo-reply",
6
+ name: "New Incident Memo Reply",
7
+ description: "Emit new event when a new memo reply is created. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/progress%20trail%20%2F%20actions%20%2F%20requests/get_incidents_id__id__progresstrail)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ incidentId: {
14
+ propDefinition: [
15
+ common.props.topdesk,
16
+ "incidentId",
17
+ ],
18
+ },
19
+ },
20
+ methods: {
21
+ ...common.methods,
22
+ getResourceFn() {
23
+ return this.topdesk.listProgressTrail;
24
+ },
25
+ getArgs() {
26
+ return {
27
+ incidentId: this.incidentId,
28
+ };
29
+ },
30
+ getTsField() {
31
+ return "creationDate";
32
+ },
33
+ paginateResults() {
34
+ return true;
35
+ },
36
+ isRelevant(item) {
37
+ const previousValue = this._getPreviousValue();
38
+ if (item.memoText !== previousValue) {
39
+ this._setPreviousValue(item.memoText);
40
+ return true;
41
+ }
42
+ return false;
43
+ },
44
+ generateMeta(item) {
45
+ return {
46
+ id: item.id,
47
+ summary: `New Incident Memo Reply: ${item.memoText}`,
48
+ ts: Date.parse(item.creationDate),
49
+ };
50
+ },
51
+ },
52
+ };
@@ -0,0 +1,52 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-new-incident-reply",
6
+ name: "New Incident Reply",
7
+ description: "Emit new event when a new incident reply is created. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/progress%20trail%20%2F%20actions%20%2F%20requests/get_incidents_id__id__progresstrail)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ incidentId: {
14
+ propDefinition: [
15
+ common.props.topdesk,
16
+ "incidentId",
17
+ ],
18
+ },
19
+ },
20
+ methods: {
21
+ ...common.methods,
22
+ getResourceFn() {
23
+ return this.topdesk.listProgressTrail;
24
+ },
25
+ getArgs() {
26
+ return {
27
+ incidentId: this.incidentId,
28
+ };
29
+ },
30
+ getTsField() {
31
+ return "creationDate";
32
+ },
33
+ paginateResults() {
34
+ return true;
35
+ },
36
+ isRelevant(item) {
37
+ const previousValue = this._getPreviousValue();
38
+ if (item.plainText !== previousValue) {
39
+ this._setPreviousValue(item.plainText);
40
+ return true;
41
+ }
42
+ return false;
43
+ },
44
+ generateMeta(item) {
45
+ return {
46
+ id: item.id,
47
+ summary: `New Incident Reply: ${item.plainText}`,
48
+ ts: Date.parse(item.creationDate),
49
+ };
50
+ },
51
+ },
52
+ };
@@ -0,0 +1,52 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "topdesk-new-incident-status",
6
+ name: "New Incident Status",
7
+ description: "Emit new event when an incident status is updated. [See the documentation](https://developers.topdesk.com/explorer/?page=incident#/incident/get_incidents_id__id_)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ incidentId: {
14
+ propDefinition: [
15
+ common.props.topdesk,
16
+ "incidentId",
17
+ ],
18
+ },
19
+ },
20
+ methods: {
21
+ ...common.methods,
22
+ getResourceFn() {
23
+ return this.topdesk.getIncident;
24
+ },
25
+ getArgs() {
26
+ return {
27
+ incidentId: this.incidentId,
28
+ };
29
+ },
30
+ getTsField() {
31
+ return "modificationDate";
32
+ },
33
+ paginateResults() {
34
+ return false;
35
+ },
36
+ isRelevant(incident) {
37
+ const previousValue = this._getPreviousValue();
38
+ if (incident.processingStatus?.id !== previousValue) {
39
+ this._setPreviousValue(incident.processingStatus?.id);
40
+ return true;
41
+ }
42
+ return false;
43
+ },
44
+ generateMeta(incident) {
45
+ return {
46
+ id: incident.id,
47
+ summary: `New Incident Status: ${incident.processingStatus?.name || `ID: ${incident.processingStatus?.id}`}`,
48
+ ts: Date.parse(incident.modificationDate),
49
+ };
50
+ },
51
+ },
52
+ };
package/topdesk.app.mjs CHANGED
@@ -651,6 +651,14 @@ export default {
651
651
  ...opts,
652
652
  });
653
653
  },
654
+ listProgressTrail({
655
+ incidentId, ...opts
656
+ }) {
657
+ return this._makeRequest({
658
+ path: `/tas/api/incidents/id/${incidentId}/progresstrail`,
659
+ ...opts,
660
+ });
661
+ },
654
662
  async *paginate({
655
663
  fn,
656
664
  fnArgs = {},
@@ -665,7 +673,7 @@ export default {
665
673
  ...fnArgs,
666
674
  params: {
667
675
  ...fnArgs.params,
668
- start: start + (fnArgs.params?.page_size || 100),
676
+ start,
669
677
  page_size: (fnArgs.params?.page_size || 100),
670
678
  },
671
679
  });