11// Macros.js: Client for the zendesk API.
22const { Client} = require ( '../client' ) ;
33
4+ /**
5+ * A recursive type that makes all properties of an object optional, including nested objects.
6+ * @template T
7+ * @typedef {Partial<{[K in keyof T]: RecursivePartial<T[K]>}> } RecursivePartial
8+ */
9+
10+ /**
11+ * A macro consists of one or more actions that modify the values of a ticket's fields
12+ * @typedef {object } Macro
13+ * @property {Array<object> } actions - Each action describes what the macro will do
14+ * @property {boolean } [active] - Useful for determining if the macro should be displayed
15+ * @property {string } [created_at] - The time the macro was created
16+ * @property {boolean } [default] - If true, the macro is a default macro
17+ * @property {string } [description] - The description of the macro
18+ * @property {number } id - The id automatically assigned when a macro is created
19+ * @property {number } [position] - The position of the macro
20+ * @property {object } [restriction] - Access to this macro. A null value allows unrestricted access for all users in the account
21+ * @property {string } title - The title of the macro
22+ * @property {string } [updated_at] - The time of the last update of the macro
23+ * @property {string } [url] - A URL to access the macro's details
24+ */
25+
26+ /**
27+ * @typedef {object } CreateOrUpdateMacro
28+ * @property {RecursivePartial<Macro> } macro - The macro object to create or update.
29+ */
30+
431/**
532 * The Macros class provides methods for interacting with the Zendesk Macros API.
633 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/ } Zendesk Macros API
@@ -13,7 +40,7 @@ class Macros extends Client {
1340
1441 /**
1542 * Lists all shared and personal macros available to the current user.
16- * @returns {Promise<Array> } Returns a promise that resolves to an array of macros.
43+ * @returns {Promise<Array<Macro> > } Returns a promise that resolves to an array of macros.
1744 * @throws {Error } Throws an error if the request fails.
1845 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-macros } Zendesk List Macros API
1946 * @example
@@ -26,7 +53,7 @@ class Macros extends Client {
2653 /**
2754 * Retrieves details of a specific macro.
2855 * @param {number } macroID - The ID of the macro to retrieve.
29- * @returns {Promise<{response: object, result: object }> } Returns a promise that resolves to the macro's details.
56+ * @returns {Promise<{response: object, result: { macro: Macro } }> } Returns a promise that resolves to the macro's details.
3057 * @throws {Error } Throws an error if the request fails.
3158 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#show-macro } Zendesk Show Macro API
3259 * @example
@@ -51,7 +78,7 @@ class Macros extends Client {
5178
5279 /**
5380 * Lists all active macros.
54- * @returns {Promise<{response: object, result: Array<object >}> } - A promise that resolves to a list of active macros.
81+ * @returns {Promise<{response: object, result: Array<Macro[] >}> } - A promise that resolves to a list of active macros.
5582 * @throws {Error } Throws an error if the request fails.
5683 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-active-macros }
5784 * @example
@@ -64,7 +91,7 @@ class Macros extends Client {
6491 /**
6592 * Lists macros based on provided parameters.
6693 * @param {object } parameters - The filtering parameters.
67- * @returns {Promise<object > } - A promise that resolves to a list of macros.
94+ * @returns {Promise<Array<Macro> > } - A promise that resolves to a list of macros.
6895 * @throws {Error } Throws an error if the request fails.
6996 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-macros }
7097 * @example
@@ -77,7 +104,7 @@ class Macros extends Client {
77104 /**
78105 * Applies a macro to a ticket.
79106 * @param {number } macroID - The ID of the macro.
80- * @returns {Promise<{response: object, result: object }> } - A promise that resolves to the applied macro's result.
107+ * @returns {Promise<{response: object, result: { ticket: RecursivePartial<import('./tickets').Ticket> } }> } - A promise that resolves to the applied macro's result.
81108 * @throws {Error } Throws an error if the request fails.
82109 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#show-macro-replica }
83110 * @example
@@ -91,7 +118,7 @@ class Macros extends Client {
91118 * Creates a macro representation derived from a ticket.
92119 * @param {number } ticketID - The ID of the ticket from which to build a macro replica.
93120 * @param {number } macroID - The ID of the macro.
94- * @returns {Promise<{response: object, result: object }> } - A promise that resolves to the macro replica.
121+ * @returns {Promise<{response: object, result: { ticket: RecursivePartial<import('./tickets').Ticket> } }> } - A promise that resolves to the macro replica.
95122 * @throws {Error } Throws an error if the request fails.
96123 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#show-macro-replica }
97124 * @example
@@ -108,7 +135,7 @@ class Macros extends Client {
108135 * @param {string } macro.title - The title of the macro.
109136 * @param {boolean } [macro.active] - Whether the macro is active.
110137 * @param {string } [macro.description] - The description of the macro.
111- * @returns {Promise<{response: object, result: object }> } - A promise that resolves to the created macro.
138+ * @returns {Promise<{response: object, result: { macro: Macro } }> } - A promise that resolves to the created macro.
112139 * @throws {Error } Throws an error if the request fails.
113140 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#create-macro }
114141 * @example
@@ -123,7 +150,7 @@ class Macros extends Client {
123150
124151 /**
125152 * Lists all macro categories available to the current user.
126- * @returns {Promise<object > } - A promise that resolves to a list of macro categories.
153+ * @returns {Promise<Array<{ categories: Array<string> }> > } - A promise that resolves to a list of macro categories.
127154 * @throws {Error } Throws an error if the request fails.
128155 * @see {@link https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-macro-categories }
129156 * @example
0 commit comments