Skip to content

Commit cbc72a0

Browse files
committed
fix(organization client): fix endpoint types, add org type
1 parent 5141990 commit cbc72a0

File tree

1 file changed

+69
-25
lines changed

1 file changed

+69
-25
lines changed

src/clients/core/organizations.js

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
// File: organizations.js
22
const {Client} = require('../client');
33

4+
/**
5+
* Organizations are typically collections of your end users, but they can also include team members.
6+
* @typedef {object} Organization
7+
* @property {string} created_at - The time the organization was created (read-only)
8+
* @property {string} [details] - Any details about the organization, such as the address
9+
* @property {string[]} [domain_names] - An array of domain names associated with this organization
10+
* @property {string} [external_id] - A unique external id to associate organizations to an external record. The id is case-insensitive
11+
* @property {number} [group_id] - New tickets from users in this organization are automatically put in this group
12+
* @property {number} [id] - Automatically assigned when the organization is created
13+
* @property {string} name - A unique name for the organization (mandatory)
14+
* @property {string} [notes] - Any notes you have about the organization
15+
* @property {{[field_name: string]: string|null}} [organization_fields] - Custom fields for this organization
16+
* @property {boolean} [shared_comments] - End users in this organization are able to comment on each other's tickets
17+
* @property {boolean} [shared_tickets] - End users in this organization are able to see each other's tickets
18+
* @property {string[]} [tags] - The tags of the organization
19+
* @property {string} updated_at - The time of the last update of the organization (read-only)
20+
* @property {string} url - The API url of this organization (read-only)
21+
*/
22+
23+
/**
24+
* @typedef {Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>} CreateOrganization
25+
*/
26+
27+
/**
28+
* @typedef {object} CreateManyOrganizations
29+
* @property {CreateOrganization[]} [organizations] - The organization object to create many organizations.
30+
*/
31+
32+
/**
33+
* @typedef {Partial<Omit<Organization, 'created_at' | 'updated_at' | 'url'>>} UpdateOrganization
34+
*/
35+
36+
/**
37+
* @typedef {object} UpdateManyOrganizations
38+
* @property {UpdateOrganization[]} [organizations] - The organization object to update many organizations.
39+
*/
40+
41+
/**
42+
* @typedef {object} OrganizationRelatedResponse
43+
* @property {object} organization_related - Information about objects related to the organization.
44+
* @property {number} organization_related.tickets_count - The number of tickets related to the organization.
45+
* @property {number} organization_related.users_count - The number of users related to the organization.
46+
*/
47+
448
/**
549
* @class
650
* Client for interacting with the Zendesk Organizations API.
@@ -14,7 +58,7 @@ class Organizations extends Client {
1458

1559
/**
1660
* Lists all organizations.
17-
* @returns {Promise<object>} The list of organizations.
61+
* @returns {Promise<Organization[]>} The list of organizations.
1862
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations}
1963
* @example const organizations = await client.organizations.list();
2064
*/
@@ -25,7 +69,7 @@ class Organizations extends Client {
2569
/**
2670
* Lists organizations associated with a specific user.
2771
* @param {number} userID - The ID of the user.
28-
* @returns {Promise<object[]>} List of organizations associated with the user.
72+
* @returns {Promise<Organization[]>} List of organizations associated with the user.
2973
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations}
3074
* @example const userOrgs = await client.organizations.listByUser(12345);
3175
*/
@@ -64,7 +108,7 @@ class Organizations extends Client {
64108
/**
65109
* Retrieves related information for a specific organization.
66110
* @param {number} organizationID - The ID of the organization.
67-
* @returns {Promise<{response: object, result: object}>} Object containing related information of the organization.
111+
* @returns {Promise<{response: object, result: OrganizationRelatedResponse}>} Object containing related information of the organization.
68112
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information}
69113
* @example const relatedInfo = await client.organizations.related(12345);
70114
*/
@@ -75,7 +119,7 @@ class Organizations extends Client {
75119
/**
76120
* Views a specific organization by its ID.
77121
* @param {number} organizationID - The ID of the organization.
78-
* @returns {Promise<{response: object, result: object}>} The organization's details.
122+
* @returns {Promise<{response: object, result: Organization}>} The organization's details.
79123
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization}
80124
* @example const organization = await client.organizations.show(12345);
81125
*/
@@ -86,7 +130,7 @@ class Organizations extends Client {
86130
/**
87131
* Retrieves details of multiple organizations based on their IDs.
88132
* @param {number[]} organizationIDs - Array of organization IDs.
89-
* @returns {Promise<object[]>} List of organizations' details.
133+
* @returns {Promise<Organization[]>} List of organizations' details.
90134
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations}
91135
* @example const orgDetails = await client.organizations.showMany([12345, 67890]);
92136
*/
@@ -103,7 +147,7 @@ class Organizations extends Client {
103147
/**
104148
* Retrieves details of multiple organizations based on their External IDs.
105149
* @param {string[]} externalOrganizationIds - Array of organization IDs.
106-
* @returns {Promise<object[]>} List of organizations' details.
150+
* @returns {Promise<Organization[]>} List of organizations' details.
107151
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations}
108152
* @example const orgDetails = await client.organizations.showMany(['12345', '67890']);
109153
*/
@@ -119,8 +163,8 @@ class Organizations extends Client {
119163

120164
/**
121165
* Creates a new organization.
122-
* @param {object} organization - The organization object to create.
123-
* @returns {Promise<{response: object, result: object}>} The created organization's details.
166+
* @param {CreateOrganization} organization - The organization object to create.
167+
* @returns {Promise<{response: object, result: Organization}>} The created organization's details.
124168
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization}
125169
* @example const newOrganization = await client.organizations.create({ name: 'New Org' });
126170
*/
@@ -130,19 +174,19 @@ class Organizations extends Client {
130174

131175
/**
132176
* Creates multiple organizations.
133-
* @param {object[]} organizations - An array of organization objects to create.
134-
* @returns {Promise<{response: object, result: object[]}>} Details of the created organizations.
177+
* @param {CreateManyOrganizations} organizations - An array of organization objects to create.
178+
* @returns {Promise<{response: object, result: Organization[]}>} Details of the created organizations.
135179
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-many-organizations}
136-
* @example const newOrganizations = await client.organizations.createMany([{ name: 'Org1' }, { name: 'Org2' }]);
180+
* @example const newOrganizations = await client.organizations.createMany({ organizations: [{ name: 'Org1' }, { name: 'Org2' }] });
137181
*/
138182
async createMany(organizations) {
139183
return this.post(['organizations', 'create_many'], organizations);
140184
}
141185

142186
/**
143187
* Creates or updates an organization.
144-
* @param {object} organization - The organization object to create or update.
145-
* @returns {Promise<{response: object, result: object}>} The created or updated organization's details.
188+
* @param {CreateOrganization|UpdateOrganization} organization - The organization object to create or update.
189+
* @returns {Promise<{response: object, result: Organization}>} The created or updated organization's details.
146190
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization}
147191
* @example const org = await client.organizations.createOrUpdate({ id: 12345, name: 'Updated Name' });
148192
*/
@@ -153,8 +197,8 @@ class Organizations extends Client {
153197
/**
154198
* Updates a specific organization by its ID.
155199
* @param {number} organizationID - The ID of the organization.
156-
* @param {object} organization - The updated organization object.
157-
* @returns {Promise<{response: object, result: object}>} The updated organization's details.
200+
* @param {Omit<UpdateOrganization, 'id'>} organization - The updated organization object.
201+
* @returns {Promise<{response: object, result: Organization}>} The updated organization's details.
158202
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization}
159203
* @example const updatedOrganization = await client.organizations.update(12345, { name: 'New Name' });
160204
*/
@@ -164,19 +208,19 @@ class Organizations extends Client {
164208

165209
/**
166210
* Updates multiple organizations.
167-
* @param {object[]} organizations - An array of organization objects to update.
168-
* @returns {Promise<{response: object, result: object[]}>} Details of the updated organizations.
211+
* @param {UpdateManyOrganizations} organizations - An array of organization objects to update.
212+
* @returns {Promise<{response: object, result: Organization[]}>} Details of the updated organizations.
169213
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-many-organizations}
170-
* @example const updatedOrganizations = await client.organizations.updateMany([{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]);
214+
* @example const updatedOrganizations = await client.organizations.updateMany({ organizations: [{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }] });
171215
*/
172216
async updateMany(organizations) {
173217
return this.put(['organizations', 'update_many'], organizations);
174218
}
175219

176220
/**
177221
* Creates or updates an organization, similar to `createOrUpdate` method.
178-
* @param {object} organization - The organization object to upsert.
179-
* @returns {Promise<{response: object, result: object}>} The created or updated organization's details.
222+
* @param {UpdateOrganization|CreateOrganization} organization - The organization object to upsert.
223+
* @returns {Promise<{response: object, result: Organization}>} The created or updated organization's details.
180224
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization}
181225
* @example const org = await client.organizations.upsert({ id: 12345, name: 'Upserted Name' });
182226
*/
@@ -235,7 +279,7 @@ class Organizations extends Client {
235279
/**
236280
* Searches organizations based on external ID.
237281
* @param {number} externalID - Search by externalID.
238-
* @returns {Promise<object[]>} List of organizations matching the search.
282+
* @returns {Promise<Organization[]>} List of organizations matching the search.
239283
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#search-organizations-by-external-id}
240284
* @example const foundOrganizations = await client.organizations.search(1234);
241285
*/
@@ -246,7 +290,7 @@ class Organizations extends Client {
246290
/**
247291
* Autocompletes organization names based on provided parameters.
248292
* @param {object} parameters - Parameters for autocomplete.
249-
* @returns {Promise<object[]>} List of organizations matching the autocomplete.
293+
* @returns {Promise<Organization[]>} List of organizations matching the autocomplete.
250294
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#autocomplete-organizations}
251295
* @example const autocompleteResults = await client.organizations.autocomplete({ name: 'Test' });
252296
*/
@@ -258,7 +302,7 @@ class Organizations extends Client {
258302
* Incrementally exports organizations with an include parameter.
259303
* @param {string|Date} startTime - Start time for incremental export.
260304
* @param {string} include - Data to include in the export.
261-
* @returns {Promise<object[]>} List of organizations in the incremental export.
305+
* @returns {Promise<Organization[]>} List of organizations in the incremental export.
262306
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export}
263307
* @example const exportedOrganizations = await client.organizations.incrementalInclude('2023-01-01T12:00:00Z', 'users');
264308
*/
@@ -273,7 +317,7 @@ class Organizations extends Client {
273317
/**
274318
* Incrementally exports organizations.
275319
* @param {string|Date} startTime - Start time for incremental export.
276-
* @returns {Promise<object[]>} List of organizations in the incremental export.
320+
* @returns {Promise<Organization[]>} List of organizations in the incremental export.
277321
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export}
278322
* @example const exportedOrganizations = await client.organizations.incremental('2023-01-01T12:00:00Z');
279323
*/
@@ -288,7 +332,7 @@ class Organizations extends Client {
288332
/**
289333
* Fetches a sample of incremental organization exports.
290334
* @param {string|Date} startTime - Start time for the sample.
291-
* @returns {Promise<{response: object, result: object[]}>} Sample list of organizations in the incremental export.
335+
* @returns {Promise<{response: object, result: Organization[]}>} Sample list of organizations in the incremental export.
292336
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-sample-export}
293337
* @example const sampleExportedOrganizations = await client.organizations.incrementalSample('2023-01-01T12:00:00Z');
294338
*/

0 commit comments

Comments
 (0)