@pipedream/zendesk 0.8.3 → 0.10.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.
@@ -0,0 +1,80 @@
1
+ import app from "../../zendesk.app.mjs";
2
+ import { parseObject } from "../../common/utils.mjs";
3
+ import { ConfigurationError } from "@pipedream/platform";
4
+
5
+ export default {
6
+ key: "zendesk-set-custom-ticket-fields",
7
+ name: "Set Custom Ticket Fields",
8
+ description: "Sets one or more custom field values on a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket).",
9
+ type: "action",
10
+ version: "0.0.1",
11
+ props: {
12
+ app,
13
+ ticketId: {
14
+ propDefinition: [
15
+ app,
16
+ "ticketId",
17
+ ],
18
+ },
19
+ customFields: {
20
+ type: "string[]",
21
+ label: "Custom Fields",
22
+ description: "Array of custom field objects. Each item should be formatted as `{\"id\": \"field_id\", \"value\": \"field_value\"}`. Example: `{\"id\": \"23129751115165\", \"value\": \"ABCDE\"}`",
23
+ },
24
+ customSubdomain: {
25
+ propDefinition: [
26
+ app,
27
+ "customSubdomain",
28
+ ],
29
+ },
30
+ },
31
+ methods: {
32
+ updateTicket({
33
+ ticketId, ...args
34
+ } = {}) {
35
+ return this.app.update({
36
+ path: `/tickets/${ticketId}`,
37
+ ...args,
38
+ });
39
+ },
40
+ },
41
+ async run({ $: step }) {
42
+ const {
43
+ ticketId,
44
+ customFields,
45
+ customSubdomain,
46
+ } = this;
47
+
48
+ // Parse custom fields from string array to objects
49
+ const parsedCustomFields = parseObject(customFields);
50
+
51
+ if (!Array.isArray(parsedCustomFields)) {
52
+ throw new ConfigurationError("Custom Fields must be an array of custom field objects");
53
+ }
54
+
55
+ // Validate custom fields structure
56
+ parsedCustomFields.forEach((field, index) => {
57
+ if (!field.id) {
58
+ throw new ConfigurationError(`Custom field at index ${index} is missing required "id" property`);
59
+ }
60
+ if (field.value === undefined) {
61
+ throw new ConfigurationError(`Custom field at index ${index} is missing required "value" property`);
62
+ }
63
+ });
64
+
65
+ const response = await this.updateTicket({
66
+ step,
67
+ ticketId,
68
+ customSubdomain,
69
+ data: {
70
+ ticket: {
71
+ custom_fields: parsedCustomFields,
72
+ },
73
+ },
74
+ });
75
+
76
+ step.export("$summary", `Successfully updated ${parsedCustomFields.length} custom field(s) on ticket ${response.ticket.id}`);
77
+
78
+ return response;
79
+ },
80
+ };
@@ -0,0 +1,25 @@
1
+ export const parseObject = (obj) => {
2
+ if (!obj) {
3
+ return {};
4
+ }
5
+ if (typeof obj === "string") {
6
+ try {
7
+ return JSON.parse(obj);
8
+ } catch {
9
+ return obj;
10
+ }
11
+ }
12
+ if (Array.isArray(obj)) {
13
+ return obj.map(parseObject);
14
+ }
15
+ if (typeof obj === "object") {
16
+ return Object.fromEntries(Object.entries(obj).map(([
17
+ key,
18
+ value,
19
+ ]) => [
20
+ key,
21
+ parseObject(value),
22
+ ]));
23
+ }
24
+ return obj;
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/zendesk",
3
- "version": "0.8.3",
3
+ "version": "0.10.0",
4
4
  "description": "Pipedream Zendesk Components",
5
5
  "main": "zendesk.app.mjs",
6
6
  "keywords": [
@@ -7,7 +7,7 @@ export default {
7
7
  key: "zendesk-new-ticket-comment-added",
8
8
  type: "source",
9
9
  description: "Emit new event when a ticket comment has been added",
10
- version: "0.0.3",
10
+ version: "0.1.0",
11
11
  dedupe: "unique",
12
12
  props: {
13
13
  app,
@@ -59,9 +59,14 @@ export default {
59
59
  },
60
60
  convertCommentsToJson(raw) {
61
61
  return [
62
- ...raw.matchAll(/#<Comment (.*?)>/g),
62
+ ...raw.matchAll(/#<Comment (.*?)(value: "[^"]*")(.*?)>/g),
63
63
  ].map((match) => {
64
- const fields = match[1]
64
+ const valueField = match[0].match(/(?<=, )value: "([^"]|\\")*[^\\]",/)?.[0];
65
+ const baseMatch = match[0].replace(/^#<Comment /, "");
66
+ const baseMatchWithoutValue = valueField
67
+ ? baseMatch.split(valueField).join("")
68
+ : baseMatch;
69
+ const fields = baseMatchWithoutValue
65
70
  .split(",")
66
71
  .map((part) => part.trim())
67
72
  .map((pair) => {
@@ -81,7 +86,15 @@ export default {
81
86
  cleaned,
82
87
  ];
83
88
  });
84
- return Object.fromEntries(fields);
89
+ return Object.fromEntries(valueField
90
+ ? [
91
+ ...fields,
92
+ [
93
+ "value",
94
+ valueField?.replace(/^value: ?/, ""),
95
+ ],
96
+ ]
97
+ : fields);
85
98
  });
86
99
  },
87
100
  isRelevant(payload) {
@@ -97,10 +110,16 @@ export default {
97
110
  },
98
111
  emitEvent(payload) {
99
112
  payload.ticketComments = this.convertCommentsToJson(payload.ticketComments);
100
- for (const comment of payload.ticketComments) {
113
+ const {
114
+ ticketComments, ...ticketData
115
+ } = payload;
116
+ for (const comment of ticketComments) {
101
117
  const ts = Date.parse(comment.created_at);
102
118
  const id = `${payload.ticketId}-${ts}`;
103
- this.$emit(comment, {
119
+ this.$emit({
120
+ ...comment,
121
+ ticketData,
122
+ }, {
104
123
  id,
105
124
  summary: comment.value,
106
125
  ts,