Skip to content

Commit 6df9710

Browse files
authored
Merge branch 'master' into master
2 parents 3a34fa6 + 0415122 commit 6df9710

File tree

10 files changed

+349
-81
lines changed

10 files changed

+349
-81
lines changed

examples/organization-upsert.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ const organization = {
1616
},
1717
};
1818

19-
client.organizations.upsert(organization, function (error, request, result) {
20-
if (error) return handleError(error);
21-
console.log(JSON.stringify(result, null, 2, true));
22-
});
19+
client.organizations.createOrUpdate(
20+
{organization},
21+
function (error, request, result) {
22+
if (error) return handleError(error);
23+
console.log(JSON.stringify(result, null, 2, true));
24+
},
25+
);
2326

2427
/**
2528
* Handles errors by logging them and exiting the process.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

0 commit comments

Comments
 (0)