@credal/actions 0.2.228 → 0.2.229
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.
- package/dist/actions/autogen/templates.js +14 -7
- package/dist/actions/autogen/types.js +28 -7
- package/dist/actions/providers/zendesk/addCommentToTicket.js +5 -3
- package/dist/actions/providers/zendesk/assignTicket.js +4 -2
- package/dist/actions/providers/zendesk/createZendeskTicket.js +8 -6
- package/dist/actions/providers/zendesk/getTicketDetails.js +4 -2
- package/dist/actions/providers/zendesk/listTickets.js +6 -6
- package/dist/actions/providers/zendesk/searchZendeskByQuery.js +6 -6
- package/dist/actions/providers/zendesk/searchZendeskTicketsByQuery.js +6 -8
- package/dist/actions/providers/zendesk/updateTicketStatus.js +4 -2
- package/dist/actions/providers/zendesk/utils/getZendeskBaseUrl.d.ts +3 -0
- package/dist/actions/providers/zendesk/utils/getZendeskBaseUrl.js +7 -0
- package/dist/actions/providers/zendesk/utils/validateSubdomain.d.ts +1 -0
- package/dist/actions/providers/zendesk/utils/validateSubdomain.js +6 -0
- package/package.json +1 -1
|
@@ -4418,7 +4418,8 @@ export const zendeskCreateZendeskTicketDefinition = {
|
|
|
4418
4418
|
},
|
|
4419
4419
|
subdomain: {
|
|
4420
4420
|
type: "string",
|
|
4421
|
-
|
|
4421
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4422
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4422
4423
|
tags: ["recommend-predefined"],
|
|
4423
4424
|
},
|
|
4424
4425
|
groupId: {
|
|
@@ -4455,7 +4456,8 @@ export const zendeskListZendeskTicketsDefinition = {
|
|
|
4455
4456
|
properties: {
|
|
4456
4457
|
subdomain: {
|
|
4457
4458
|
type: "string",
|
|
4458
|
-
|
|
4459
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4460
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4459
4461
|
tags: ["recommend-predefined"],
|
|
4460
4462
|
},
|
|
4461
4463
|
status: {
|
|
@@ -4499,7 +4501,8 @@ export const zendeskGetTicketDetailsDefinition = {
|
|
|
4499
4501
|
},
|
|
4500
4502
|
subdomain: {
|
|
4501
4503
|
type: "string",
|
|
4502
|
-
|
|
4504
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4505
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4503
4506
|
tags: ["recommend-predefined"],
|
|
4504
4507
|
},
|
|
4505
4508
|
},
|
|
@@ -4532,7 +4535,8 @@ export const zendeskUpdateTicketStatusDefinition = {
|
|
|
4532
4535
|
},
|
|
4533
4536
|
subdomain: {
|
|
4534
4537
|
type: "string",
|
|
4535
|
-
|
|
4538
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4539
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4536
4540
|
tags: ["recommend-predefined"],
|
|
4537
4541
|
},
|
|
4538
4542
|
status: {
|
|
@@ -4559,7 +4563,8 @@ export const zendeskAddCommentToTicketDefinition = {
|
|
|
4559
4563
|
},
|
|
4560
4564
|
subdomain: {
|
|
4561
4565
|
type: "string",
|
|
4562
|
-
|
|
4566
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4567
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4563
4568
|
tags: ["recommend-predefined"],
|
|
4564
4569
|
},
|
|
4565
4570
|
body: {
|
|
@@ -4604,7 +4609,8 @@ export const zendeskAssignTicketDefinition = {
|
|
|
4604
4609
|
},
|
|
4605
4610
|
subdomain: {
|
|
4606
4611
|
type: "string",
|
|
4607
|
-
|
|
4612
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4613
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4608
4614
|
tags: ["recommend-predefined"],
|
|
4609
4615
|
},
|
|
4610
4616
|
assigneeEmail: {
|
|
@@ -4627,7 +4633,8 @@ export const zendeskSearchZendeskByQueryDefinition = {
|
|
|
4627
4633
|
properties: {
|
|
4628
4634
|
subdomain: {
|
|
4629
4635
|
type: "string",
|
|
4630
|
-
|
|
4636
|
+
pattern: "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
|
|
4637
|
+
description: "The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix",
|
|
4631
4638
|
tags: ["recommend-predefined"],
|
|
4632
4639
|
},
|
|
4633
4640
|
query: {
|
|
@@ -1596,7 +1596,10 @@ export const bingGetTopNSearchResultUrlsOutputSchema = z.object({
|
|
|
1596
1596
|
export const zendeskCreateZendeskTicketParamsSchema = z.object({
|
|
1597
1597
|
subject: z.string().describe("The subject of the ticket"),
|
|
1598
1598
|
body: z.string().describe("The body of the ticket").optional(),
|
|
1599
|
-
subdomain: z
|
|
1599
|
+
subdomain: z
|
|
1600
|
+
.string()
|
|
1601
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1602
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1600
1603
|
groupId: z.coerce.number().describe("The ID of the group to assign the ticket to").optional(),
|
|
1601
1604
|
});
|
|
1602
1605
|
export const zendeskCreateZendeskTicketOutputSchema = z.object({
|
|
@@ -1604,7 +1607,10 @@ export const zendeskCreateZendeskTicketOutputSchema = z.object({
|
|
|
1604
1607
|
ticketUrl: z.string().describe("The URL of the ticket created").optional(),
|
|
1605
1608
|
});
|
|
1606
1609
|
export const zendeskListZendeskTicketsParamsSchema = z.object({
|
|
1607
|
-
subdomain: z
|
|
1610
|
+
subdomain: z
|
|
1611
|
+
.string()
|
|
1612
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1613
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1608
1614
|
status: z.string().describe("Filter tickets by status (new, open, pending, hold, solved, closed)").optional(),
|
|
1609
1615
|
});
|
|
1610
1616
|
export const zendeskListZendeskTicketsOutputSchema = z.object({
|
|
@@ -1613,14 +1619,20 @@ export const zendeskListZendeskTicketsOutputSchema = z.object({
|
|
|
1613
1619
|
});
|
|
1614
1620
|
export const zendeskGetTicketDetailsParamsSchema = z.object({
|
|
1615
1621
|
ticketId: z.string().describe("The ID of the ticket"),
|
|
1616
|
-
subdomain: z
|
|
1622
|
+
subdomain: z
|
|
1623
|
+
.string()
|
|
1624
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1625
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1617
1626
|
});
|
|
1618
1627
|
export const zendeskGetTicketDetailsOutputSchema = z.object({
|
|
1619
1628
|
ticket: z.object({}).catchall(z.any()).describe("The details of the ticket"),
|
|
1620
1629
|
});
|
|
1621
1630
|
export const zendeskUpdateTicketStatusParamsSchema = z.object({
|
|
1622
1631
|
ticketId: z.string().describe("The ID of the ticket to update"),
|
|
1623
|
-
subdomain: z
|
|
1632
|
+
subdomain: z
|
|
1633
|
+
.string()
|
|
1634
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1635
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1624
1636
|
status: z
|
|
1625
1637
|
.string()
|
|
1626
1638
|
.describe('The state of the ticket. If your account has activated custom ticket statuses, this is the ticket\'s status category. Allowed values are "new", "open", "pending", "hold", "solved", or "closed".'),
|
|
@@ -1628,7 +1640,10 @@ export const zendeskUpdateTicketStatusParamsSchema = z.object({
|
|
|
1628
1640
|
export const zendeskUpdateTicketStatusOutputSchema = z.void();
|
|
1629
1641
|
export const zendeskAddCommentToTicketParamsSchema = z.object({
|
|
1630
1642
|
ticketId: z.string().describe("The ID of the ticket to update"),
|
|
1631
|
-
subdomain: z
|
|
1643
|
+
subdomain: z
|
|
1644
|
+
.string()
|
|
1645
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1646
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1632
1647
|
body: z.string().describe("The body of the comment"),
|
|
1633
1648
|
public: z.boolean().describe("Whether the comment should be public (defaults to true)").optional(),
|
|
1634
1649
|
});
|
|
@@ -1638,12 +1653,18 @@ export const zendeskAddCommentToTicketOutputSchema = z.object({
|
|
|
1638
1653
|
});
|
|
1639
1654
|
export const zendeskAssignTicketParamsSchema = z.object({
|
|
1640
1655
|
ticketId: z.string().describe("The ID of the ticket to update"),
|
|
1641
|
-
subdomain: z
|
|
1656
|
+
subdomain: z
|
|
1657
|
+
.string()
|
|
1658
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1659
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1642
1660
|
assigneeEmail: z.string().describe("The email address of the agent to assign the ticket to"),
|
|
1643
1661
|
});
|
|
1644
1662
|
export const zendeskAssignTicketOutputSchema = z.void();
|
|
1645
1663
|
export const zendeskSearchZendeskByQueryParamsSchema = z.object({
|
|
1646
|
-
subdomain: z
|
|
1664
|
+
subdomain: z
|
|
1665
|
+
.string()
|
|
1666
|
+
.regex(new RegExp("^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$"))
|
|
1667
|
+
.describe("The hostname-label subdomain of the Zendesk account, without a protocol, path, or .zendesk.com suffix"),
|
|
1647
1668
|
query: z
|
|
1648
1669
|
.string()
|
|
1649
1670
|
.describe('Search query string that can include filters like status, priority, tags, assignee, etc. Examples - status:open, priority:high, tags:bug, assignee:user@example.com, or combination like "status:open priority:high"'),
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const addCommentToTicket = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, ticketId, body, public: isPublic } = params;
|
|
6
|
-
const url = `https://${subdomain}.zendesk.com/api/v2/tickets/${ticketId}.json`;
|
|
7
7
|
if (!authToken) {
|
|
8
8
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
9
9
|
}
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL(`/api/v2/tickets/${ticketId}.json`, zendeskBaseUrl);
|
|
10
12
|
const axiosClient = createAxiosClientWithRetries({ timeout: 20000, retryCount: 5 });
|
|
11
13
|
try {
|
|
12
14
|
await axiosClient.request({
|
|
13
|
-
url:
|
|
15
|
+
url: apiEndpoint.toString(),
|
|
14
16
|
method: "PUT",
|
|
15
17
|
headers: {
|
|
16
18
|
"Content-Type": "application/json",
|
|
@@ -27,7 +29,7 @@ const addCommentToTicket = async ({ params, authParams, }) => {
|
|
|
27
29
|
});
|
|
28
30
|
return {
|
|
29
31
|
success: true,
|
|
30
|
-
ticketUrl:
|
|
32
|
+
ticketUrl: new URL(`/agent/tickets/${ticketId}`, zendeskBaseUrl).toString(),
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
catch (error) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const updateTicketStatus = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, ticketId, assigneeEmail } = params;
|
|
6
|
-
const url = `https://${subdomain}.zendesk.com/api/v2/tickets/${ticketId}.json`;
|
|
7
7
|
if (!authToken) {
|
|
8
8
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
9
9
|
}
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL(`/api/v2/tickets/${ticketId}.json`, zendeskBaseUrl);
|
|
10
12
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
11
13
|
await axiosClient.request({
|
|
12
|
-
url:
|
|
14
|
+
url: apiEndpoint.toString(),
|
|
13
15
|
method: "PUT",
|
|
14
16
|
headers: {
|
|
15
17
|
"Content-Type": "application/json",
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const createZendeskTicket = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, subject, body, groupId } = params;
|
|
6
|
-
|
|
7
|
+
if (!authToken) {
|
|
8
|
+
throw new Error(MISSING_AUTH_TOKEN);
|
|
9
|
+
}
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL("/api/v2/tickets.json", zendeskBaseUrl);
|
|
7
12
|
const payload = {
|
|
8
13
|
ticket: {
|
|
9
14
|
subject,
|
|
@@ -13,11 +18,8 @@ const createZendeskTicket = async ({ params, authParams, }) => {
|
|
|
13
18
|
group_id: groupId,
|
|
14
19
|
},
|
|
15
20
|
};
|
|
16
|
-
if (!authToken) {
|
|
17
|
-
throw new Error(MISSING_AUTH_TOKEN);
|
|
18
|
-
}
|
|
19
21
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
20
|
-
const response = await axiosClient.post(
|
|
22
|
+
const response = await axiosClient.post(apiEndpoint.toString(), payload, {
|
|
21
23
|
headers: {
|
|
22
24
|
"Content-Type": "application/json",
|
|
23
25
|
Authorization: `Bearer ${authToken}`,
|
|
@@ -25,7 +27,7 @@ const createZendeskTicket = async ({ params, authParams, }) => {
|
|
|
25
27
|
});
|
|
26
28
|
return {
|
|
27
29
|
ticketId: response.data.ticket.id,
|
|
28
|
-
ticketUrl:
|
|
30
|
+
ticketUrl: new URL(`/requests/${response.data.ticket.id}`, zendeskBaseUrl).toString(),
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
33
|
export default createZendeskTicket;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const getZendeskTicketDetails = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, ticketId } = params;
|
|
6
|
-
const url = `https://${subdomain}.zendesk.com/api/v2/tickets/${ticketId}.json`;
|
|
7
7
|
if (!authToken) {
|
|
8
8
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
9
9
|
}
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL(`/api/v2/tickets/${ticketId}.json`, zendeskBaseUrl);
|
|
10
12
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
11
13
|
const response = await axiosClient.request({
|
|
12
|
-
url:
|
|
14
|
+
url: apiEndpoint.toString(),
|
|
13
15
|
method: "GET",
|
|
14
16
|
headers: {
|
|
15
17
|
"Content-Type": "application/json",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const listZendeskTickets = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, status } = params;
|
|
@@ -7,19 +8,18 @@ const listZendeskTickets = async ({ params, authParams, }) => {
|
|
|
7
8
|
const threeMonthsAgo = new Date();
|
|
8
9
|
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
|
|
9
10
|
const formattedDate = threeMonthsAgo.toISOString().split("T")[0];
|
|
10
|
-
// Endpoint for getting tickets
|
|
11
|
-
const url = `https://${subdomain}.zendesk.com/api/v2/tickets.json`;
|
|
12
11
|
if (!authToken) {
|
|
13
12
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
14
13
|
}
|
|
14
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
15
|
+
const apiEndpoint = new URL("/api/v2/tickets.json", zendeskBaseUrl);
|
|
15
16
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
16
17
|
// Add query parameters for filtering
|
|
17
|
-
|
|
18
|
-
queryParams.append("created_after", formattedDate);
|
|
18
|
+
apiEndpoint.searchParams.set("created_after", formattedDate);
|
|
19
19
|
if (status) {
|
|
20
|
-
|
|
20
|
+
apiEndpoint.searchParams.set("status", status);
|
|
21
21
|
}
|
|
22
|
-
const response = await axiosClient.get(
|
|
22
|
+
const response = await axiosClient.get(apiEndpoint.toString(), {
|
|
23
23
|
headers: {
|
|
24
24
|
"Content-Type": "application/json",
|
|
25
25
|
Authorization: `Bearer ${authToken}`,
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const searchZendeskByQuery = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, query, objectType = "ticket", limit = 100 } = params;
|
|
6
|
-
// Endpoint for searching Zendesk objects
|
|
7
|
-
const url = `https://${subdomain}.zendesk.com/api/v2/search.json`;
|
|
8
7
|
if (!authToken) {
|
|
9
8
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
10
9
|
}
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL("/api/v2/search.json", zendeskBaseUrl);
|
|
11
12
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
12
13
|
// Build search query parameters
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const response = await axiosClient.get(`${url}?${queryParams.toString()}`, {
|
|
14
|
+
apiEndpoint.searchParams.set("query", `type:${objectType} ${query}`);
|
|
15
|
+
apiEndpoint.searchParams.set("per_page", limit.toString());
|
|
16
|
+
const response = await axiosClient.get(apiEndpoint.toString(), {
|
|
17
17
|
headers: {
|
|
18
18
|
"Content-Type": "application/json",
|
|
19
19
|
Authorization: `Bearer ${authToken}`,
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
-
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
4
4
|
const searchZendeskTicketsByQuery = async ({ params, authParams, }) => {
|
|
5
5
|
const { authToken } = authParams;
|
|
6
6
|
const { subdomain, query, limit = 100 } = params;
|
|
7
7
|
if (!authToken) {
|
|
8
8
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
const url = new URL(`https://${subdomain}.zendesk.com/api/v2/search.json`);
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL("/api/v2/search.json", zendeskBaseUrl);
|
|
14
12
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
15
13
|
// Strip any type: filters from the incoming query so it can't target other resource types,
|
|
16
14
|
// then force the search to tickets only
|
|
@@ -18,9 +16,9 @@ const searchZendeskTicketsByQuery = async ({ params, authParams, }) => {
|
|
|
18
16
|
.replace(/\btype:\S+/gi, "")
|
|
19
17
|
.replace(/\s+/g, " ")
|
|
20
18
|
.trim();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const response = await axiosClient.get(
|
|
19
|
+
apiEndpoint.searchParams.set("query", `type:ticket ${sanitizedQuery}`.trim());
|
|
20
|
+
apiEndpoint.searchParams.set("per_page", limit.toString());
|
|
21
|
+
const response = await axiosClient.get(apiEndpoint.toString(), {
|
|
24
22
|
headers: {
|
|
25
23
|
"Content-Type": "application/json",
|
|
26
24
|
Authorization: `Bearer ${authToken}`,
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { createAxiosClientWithRetries } from "../../util/axiosClient.js";
|
|
2
2
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
3
|
+
import { getZendeskBaseUrl } from "./utils/getZendeskBaseUrl.js";
|
|
3
4
|
const updateTicketStatus = async ({ params, authParams, }) => {
|
|
4
5
|
const { authToken } = authParams;
|
|
5
6
|
const { subdomain, ticketId, status } = params;
|
|
6
|
-
const url = `https://${subdomain}.zendesk.com/api/v2/tickets/${ticketId}.json`;
|
|
7
7
|
if (!authToken) {
|
|
8
8
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
9
9
|
}
|
|
10
|
+
const zendeskBaseUrl = getZendeskBaseUrl({ subdomain });
|
|
11
|
+
const apiEndpoint = new URL(`/api/v2/tickets/${ticketId}.json`, zendeskBaseUrl);
|
|
10
12
|
const axiosClient = createAxiosClientWithRetries({ timeout: 10000, retryCount: 4 });
|
|
11
13
|
await axiosClient.request({
|
|
12
|
-
url:
|
|
14
|
+
url: apiEndpoint.toString(),
|
|
13
15
|
method: "PUT",
|
|
14
16
|
headers: {
|
|
15
17
|
"Content-Type": "application/json",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const ZENDESK_SUBDOMAIN_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
2
|
+
export const getZendeskBaseUrl = ({ subdomain }) => {
|
|
3
|
+
if (!ZENDESK_SUBDOMAIN_PATTERN.test(subdomain)) {
|
|
4
|
+
throw new Error("Invalid Zendesk subdomain");
|
|
5
|
+
}
|
|
6
|
+
return new URL(`https://${subdomain}.zendesk.com/`);
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateZendeskSubdomain: (subdomain: string) => void;
|