Skip to content

Commit cd3749c

Browse files
authored
Merge pull request #442 from KiraLT/master
Better types for brands, tickets, macros, webhooks, articles
2 parents 6873fa8 + 09893b2 commit cd3749c

File tree

7 files changed

+246
-44
lines changed

7 files changed

+246
-44
lines changed

src/clients/core/brand.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
// File: brands.js
22
const {Client} = require('../client');
3+
4+
/**
5+
* Brands are your customer-facing identities.
6+
* @typedef {object} Brand
7+
* @property {boolean} [active] - If the brand is set as active
8+
* @property {string} [brand_url] - The url of the brand
9+
* @property {string} created_at - The time the brand was created
10+
* @property {boolean} [default] - Is the brand the default brand for this account
11+
* @property {boolean} [has_help_center] - If the brand has a Help Center
12+
* @property {'enabled' | 'disabled' | 'restricted'} help_center_state - The state of the Help Center
13+
* @property {string | null} [host_mapping] - The hostmapping to this brand, if any. Only admins view this property
14+
* @property {number} id - The ID automatically assigned when the brand is created
15+
* @property {boolean} [is_deleted] - If the brand object is deleted or not
16+
* @property {object | null} [logo] - A file represented as an Attachment object
17+
* @property {string} name - The name of the brand
18+
* @property {string} [signature_template] - The signature template for a brand
19+
* @property {string} subdomain - The subdomain of the brand
20+
* @property {number[]} [ticket_form_ids] - The ids of ticket forms that are available for use by a brand
21+
* @property {string} [updated_at] - The time of the last update of the brand
22+
* @property {string} [url] - The API url of this brand
23+
*/
24+
25+
/**
26+
* @typedef {object} CreateOrUpdateBrand
27+
* @property {Partial<Brand>} brand - The brand object to create or update.
28+
*/
29+
330
/**
431
* Class representing the Brand API endpoints.
532
* @see {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/}
633
*/
7-
class Brand extends Client {
34+
class Brands extends Client {
835
constructor(options) {
936
super(options);
1037
this.jsonAPINames = ['brands'];
1138
}
1239

1340
/**
1441
* List all brands.
15-
* @returns {Promise<{response: object, result: Array<object>}>} The list of brands.
42+
* @returns {Promise<{response: object, result: Array<Brand>}>} The list of brands.
1643
* @see {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#list-brands}
1744
* @example const brands = await client.brands.list();
1845
*/
@@ -23,7 +50,7 @@ class Brand extends Client {
2350
/**
2451
* Show a specific brand by ID.
2552
* @param {number} brandId - The ID of the brand.
26-
* @returns {Promise<{response: object, result: object}>} The brand details.
53+
* @returns {Promise<{response: object, result: { brand: Brand }}>} The brand details.
2754
* @see {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#show-a-brand}
2855
* @example const brand = await client.brands.show(47);
2956
*/
@@ -33,8 +60,8 @@ class Brand extends Client {
3360

3461
/**
3562
* Create a new brand.
36-
* @param {object} brand - The brand data.
37-
* @returns {Promise<{response: object, result: object}>} The created brand details.
63+
* @param {CreateOrUpdateBrand} brand - The brand data.
64+
* @returns {Promise<{response: object, result: { brand: Brand }}>} The created brand details.
3865
* @see {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#create-brand}
3966
* @example const newBrand = await client.brands.create({name: "Brand 1", subdomain: "Brand1"});
4067
*/
@@ -44,9 +71,9 @@ class Brand extends Client {
4471

4572
/**
4673
* Update an existing brand.
47-
* @param {object} brand - The updated brand data.
74+
* @param {CreateOrUpdateBrand} brand - The updated brand data.
4875
* @param {number} brandId - The ID of the brand to update.
49-
* @returns {Promise<{response: object, result: object}>} The updated brand details.
76+
* @returns {Promise<{response: object, result: { brand: Brand }}>} The updated brand details.
5077
* @see {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#update-a-brand}
5178
* @example const updatedBrand = await client.brands.update({name: "Updated Brand"}, 47);
5279
*/
@@ -93,4 +120,4 @@ class Brand extends Client {
93120
}
94121
}
95122

96-
exports.Brand = Brand;
123+
exports.Brands = Brands;

src/clients/core/macros.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
// Macros.js: Client for the zendesk API.
22
const {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

src/clients/core/tickets.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const {Client} = require('../client');
3939
* @property {boolean} public - true if a public comment; false if an internal note. The initial value set on ticket creation persists for any additional comment unless you change it
4040
* @property {string} type - Comment or VoiceComment. The JSON object for adding voice comments to tickets is different. See Adding voice comments to tickets
4141
* @property {string[]} [uploads] - List of tokens received from uploading files for comment attachments. The files are attached by creating or updating tickets with the tokens. See Attaching files in Tickets
42-
* @property {object} [via] - Describes how the object was created. See the Via object reference
42+
* @property {Via} [via] - Describes how the object was created. See the Via object reference
4343
*/
4444

4545
/**
@@ -93,7 +93,7 @@ const {Client} = require('../client');
9393
* @property {string} updated_at - When this record last got updated
9494
* @property {string} [updated_stamp] - Write only. Datetime of last update received from API. See the safe_update property
9595
* @property {string} url - The API url of this ticket
96-
* @property {object} [via] - For more information, see the Via object reference
96+
* @property {Via} [via] - For more information, see the Via object reference
9797
* @property {number} [via_followup_source_id] - POST requests only. The id of a closed ticket when creating a follow-up ticket. See Creating a follow-up ticket
9898
* @property {number} [via_id] - Write only. For more information, see the Via object reference
9999
* @property {object} [voice_comment] - Write only. See Creating voicemail ticket
@@ -127,6 +127,12 @@ const {Client} = require('../client');
127127
* @property {Array<Ticket>} [tickets] - The ticket object to create many tickets.
128128
*/
129129

130+
/**
131+
* @typedef {object} Via
132+
* @property {string} [channel] - How the ticket or event was created expressed as a via type or via id
133+
* @property {object} source - For some channels a source object gives more information about how or why the ticket or event was created
134+
*/
135+
130136
/**
131137
* @class
132138
* Client for the Zendesk API - Tickets.
@@ -523,7 +529,7 @@ class Tickets extends Client {
523529
/**
524530
* Retrieve comments associated with a specific ticket.
525531
* @param {number} ticketId - The ID of the ticket to retrieve comments for.
526-
* @returns {Promise<Array>} A promise that resolves with an array of comments associated with the ticket.
532+
* @returns {Promise<Array<TicketComment>>} A promise that resolves with an array of comments associated with the ticket.
527533
* @throws {Error} If `ticketId` is not a valid number.
528534
* @see {@link https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/}
529535
* @example

src/clients/core/webhooks.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
// Webhooks.js: Client for the zendesk API.
22
const {Client} = require('../client');
33

4+
/**
5+
* A webhook sends an HTTP request to a specified URL in response to an activity in Zendesk Support.
6+
* @typedef {object} Webhook
7+
* @property {object} [authentication] - Adds authentication to the webhook's HTTP requests. See Webhook security and authentication
8+
* @property {string} [created_at] - When the webhook was created (read-only)
9+
* @property {string} [created_by] - id of the user who created the webhook. "-1" represents the Zendesk system (read-only)
10+
* @property {object} [custom_headers] - Custom headers to deliver additional non-credential info to destinations
11+
* @property {string} [description] - Webhook description
12+
* @property {string} endpoint - The destination URL that the webhook notifies when Zendesk events occur
13+
* @property {object} [external_source] - External source by which a webhook is created, e.g. Zendesk Marketplace
14+
* @property {'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'} http_method - HTTP method used for the webhook's requests. To subscribe the webhook to Zendesk events, this must be "POST"
15+
* @property {string} id - An auto-generated webhook id (read-only)
16+
* @property {string} name - Webhook name
17+
* @property {'json' | 'xml' | 'form_encoded'} request_format - The format of the data that the webhook will send. To subscribe the webhook to Zendesk events, this must be "json"
18+
* @property {WebhookSigningSecret} [signing_secret] - Signing secret used to verify webhook requests
19+
* @property {'active' | 'inactive'} status - Current status of the webhook
20+
* @property {Array} [subscriptions] - Event subscriptions for the webhook. To subscribe the webhook to Zendesk events, specify one or more event types
21+
* @property {string} [updated_at] - When the webhook was last updated (read-only)
22+
* @property {string} [updated_by] - id of the user who last updated the webhook (read-only)
23+
*/
24+
25+
/**
26+
* @typedef {object} CreateOrUpdateWebhook
27+
* @property {Partial<Webhook>} webhook - The webhook object to create or update.
28+
*/
29+
30+
/**
31+
* @typedef {object} WebhookSigningSecret
32+
* @property {string} algorithm - The algorithm used to generate the signing secret like "sha256"
33+
* @property {string} secret - The signing secret used to verify webhook requests
34+
*/
35+
436
/**
537
* Webhooks client for interacting with the Zendesk Webhooks API.
638
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/}
@@ -14,7 +46,7 @@ class Webhooks extends Client {
1446

1547
/**
1648
* List all webhooks.
17-
* @returns {Promise<object>} A promise that resolves to the list of webhooks.
49+
* @returns {Promise<Webhook>} A promise that resolves to the list of webhooks.
1850
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#list-webhooks}
1951
* @example const webhooks = await client.webhooks.list();
2052
*/
@@ -25,7 +57,7 @@ class Webhooks extends Client {
2557
/**
2658
* Retrieve a specific webhook by ID.
2759
* @param {string} webhookID - The ID of the webhook to retrieve.
28-
* @returns {Promise<{response: object, result: object}>} A promise that resolves to the specified webhook.
60+
* @returns {Promise<{response: object, result: Webhook}>} A promise that resolves to the specified webhook.
2961
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#show-webhook}
3062
* @example const webhook = await client.webhooks.show('webhookID123');
3163
*/
@@ -35,8 +67,8 @@ class Webhooks extends Client {
3567

3668
/**
3769
* Create a new webhook.
38-
* @param {object} webhook - The webhook data to create.
39-
* @returns {Promise<{response: object, result: object}>} A promise that resolves to the created webhook.
70+
* @param {CreateOrUpdateWebhook} webhook - The webhook data to create.
71+
* @returns {Promise<{response: object, result: Webhook}>} A promise that resolves to the created webhook.
4072
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#create-or-clone-webhook}
4173
* @example
4274
* const newWebhook = {
@@ -51,7 +83,7 @@ class Webhooks extends Client {
5183
/**
5284
* Update a specific webhook by ID.
5385
* @param {string} webhookID - The ID of the webhook to update.
54-
* @param {object} webhook - The updated webhook data.
86+
* @param {CreateOrUpdateWebhook} webhook - The updated webhook data.
5587
* @returns {Promise<{response: object, result: object}>} A promise that resolves to the updated webhook.
5688
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#update-webhook}
5789
* @example
@@ -128,7 +160,7 @@ class Webhooks extends Client {
128160
/**
129161
* Retrieve the signing secret of a specific webhook.
130162
* @param {string} webhookID - The ID of the webhook.
131-
* @returns {Promise<{response: object, result: object}>} A promise that resolves to the signing secret.
163+
* @returns {Promise<{response: object, result: {signing_secret: WebhookSigningSecret}}>} A promise that resolves to the signing secret.
132164
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#show-webhook-signing-secret}
133165
* @example const secret = await client.webhooks.getSigningSecret('webhookID123');
134166
*/
@@ -139,7 +171,7 @@ class Webhooks extends Client {
139171
/**
140172
* Reset the signing secret for a specific webhook.
141173
* @param {string} webhookID - The ID of the webhook.
142-
* @returns {Promise<{response: object, result: object}>} A promise that resolves to the new signing secret.
174+
* @returns {Promise<{response: object, result: {signing_secret: WebhookSigningSecret}}>} A promise that resolves to the new signing secret.
143175
* @see {@link https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#reset-webhook-signing-secret}
144176
* @example const newSecret = await client.webhooks.resetSigningSecret('webhookID123');
145177
*/

0 commit comments

Comments
 (0)