@pipedream/connectwise_psa 0.1.1 → 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.
@@ -1,10 +1,11 @@
1
+ import { parseObjectEntries } from "../../common/utils.mjs";
1
2
  import connectwise from "../../connectwise_psa.app.mjs";
2
3
 
3
4
  export default {
4
5
  key: "connectwise_psa-create-contact",
5
6
  name: "Create Contact",
6
7
  description: "Creates a new contact in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Contacts/postCompanyContacts)",
7
- version: "0.0.1",
8
+ version: "0.1.0",
8
9
  type: "action",
9
10
  props: {
10
11
  connectwise,
@@ -91,6 +92,18 @@ export default {
91
92
  "country",
92
93
  ],
93
94
  },
95
+ isDefault: {
96
+ type: "boolean",
97
+ label: "Primary Contact",
98
+ description: "Whether the contact is the primary (default) contact for the company",
99
+ optional: true,
100
+ },
101
+ additionalOptions: {
102
+ type: "object",
103
+ label: "Additional Options",
104
+ description: "Additional parameters to send in the request. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Contacts/postCompanyContacts) for available parameters. Values will be parsed as JSON where applicable.",
105
+ optional: true,
106
+ },
94
107
  },
95
108
  async run({ $ }) {
96
109
  const communicationItems = [];
@@ -145,6 +158,8 @@ export default {
145
158
  id: this.department,
146
159
  }
147
160
  : undefined,
161
+ defaultFlag: this.isDefault,
162
+ ...(this.additionalOptions && parseObjectEntries(this.additionalOptions)),
148
163
  },
149
164
  });
150
165
  $.export("$summary", `Successfully created contact with ID: ${response.id}`);
@@ -4,7 +4,7 @@ export default {
4
4
  key: "connectwise_psa-create-ticket",
5
5
  name: "Create Ticket",
6
6
  description: "Creates a new ticket in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Tickets/postServiceTickets)",
7
- version: "0.0.1",
7
+ version: "0.1.0",
8
8
  type: "action",
9
9
  props: {
10
10
  connectwise,
@@ -31,6 +31,23 @@ export default {
31
31
  "priority",
32
32
  ],
33
33
  },
34
+ note: {
35
+ type: "string[]",
36
+ label: "Note(s)",
37
+ description: "Text content of one or more notes to add to the ticket",
38
+ optional: true,
39
+ },
40
+ },
41
+ methods: {
42
+ createTicketNote({
43
+ id, ...args
44
+ }) {
45
+ return this.connectwise._makeRequest({
46
+ method: "POST",
47
+ path: `/service/tickets/${id}/notes`,
48
+ ...args,
49
+ });
50
+ },
34
51
  },
35
52
  async run({ $ }) {
36
53
  const response = await this.connectwise.createTicket({
@@ -52,7 +69,38 @@ export default {
52
69
  : undefined,
53
70
  },
54
71
  });
55
- $.export("$summary", `Successfully created ticket with ID: ${response.id}`);
56
- return response;
72
+ const { id } = response;
73
+ const { note } = this;
74
+ const createdNotes = [];
75
+ if (id && note?.length) {
76
+ const notes = Array.isArray(note)
77
+ ? note
78
+ : [
79
+ note,
80
+ ];
81
+ for (let note of notes) {
82
+ const response = await this.createTicketNote({
83
+ $,
84
+ id,
85
+ data: {
86
+ text: note,
87
+ detailDescriptionFlag: true,
88
+ },
89
+ });
90
+ createdNotes.push(response);
91
+ }
92
+ }
93
+ const amountNotes = createdNotes.length;
94
+ $.export("$summary", `Successfully created ticket (ID: ${id})${amountNotes
95
+ ? ` and added ${amountNotes} notes`
96
+ : ""}`);
97
+ return {
98
+ ...(amountNotes
99
+ ? {
100
+ createdNotes,
101
+ }
102
+ : undefined),
103
+ ...response,
104
+ };
57
105
  },
58
106
  };
@@ -0,0 +1,22 @@
1
+ function optionalParseAsJSON(value) {
2
+ try {
3
+ return JSON.parse(value);
4
+ } catch (e) {
5
+ return value;
6
+ }
7
+ }
8
+
9
+ export function parseObjectEntries(value) {
10
+ const obj = typeof value === "string"
11
+ ? JSON.parse(value)
12
+ : value;
13
+ return Object.fromEntries(
14
+ Object.entries(obj).map(([
15
+ key,
16
+ value,
17
+ ]) => [
18
+ key,
19
+ optionalParseAsJSON(value),
20
+ ]),
21
+ );
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/connectwise_psa",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream Connectwise PSA Components",
5
5
  "main": "connectwise_psa.app.mjs",
6
6
  "keywords": [