Skip to content

Commit c9b52ca

Browse files
committed
chore: update xo and fix lint
1 parent 2cfe5dc commit c9b52ca

11 files changed

+159
-84
lines changed

examples/groupmemberships-list-group.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ const client = zd.createClient({
88
remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
99
});
1010

11-
client.groups.list().then(function (groups) {
12-
const group = groups[0];
13-
client.groupmemberships.listByGroup(group.id).then(function (memberships) {
11+
/**
12+
*
13+
*/
14+
async function listGroupMemberships() {
15+
try {
16+
const groups = await client.groups.list();
17+
const group = groups[0];
18+
19+
if (!group) {
20+
console.log('No groups found.');
21+
return;
22+
}
23+
24+
const memberships = await client.groupmemberships.listByGroup(group.id);
1425
console.log(JSON.stringify(memberships));
15-
});
16-
});
26+
} catch (error) {
27+
console.error('Error fetching group memberships:', error);
28+
}
29+
}
30+
31+
listGroupMemberships();

examples/groupmemberships-list-user.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ const client = zd.createClient({
88
remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
99
});
1010

11-
client.users.list().then(function (users) {
12-
const user = users[0];
13-
client.groupmemberships.listByUser(user.id).then(function (memberships) {
11+
/**
12+
*
13+
*/
14+
async function listUserMemberships() {
15+
try {
16+
const users = await client.users.list();
17+
const user = users[0];
18+
19+
if (!user) {
20+
console.log('No users found.');
21+
return;
22+
}
23+
24+
const memberships = await client.groupmemberships.listByUser(user.id);
1425
console.log(JSON.stringify(memberships));
15-
});
16-
});
26+
} catch (error) {
27+
console.error('Error fetching user memberships:', error);
28+
}
29+
}
30+
31+
listUserMemberships();

examples/ticketaudits-list.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ const client = zd.createClient({
88
remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
99
});
1010

11-
client.tickets.list().then(function (tickets) {
12-
const ticket = tickets[0];
13-
client.ticketaudits.list(ticket.id).then(function (audits) {
11+
/**
12+
*
13+
*/
14+
async function listTicketAudits() {
15+
try {
16+
const tickets = await client.tickets.list();
17+
const ticket = tickets[0];
18+
19+
if (!ticket) {
20+
console.log('No tickets found.');
21+
return;
22+
}
23+
24+
const audits = await client.ticketaudits.list(ticket.id);
1425
console.log(JSON.stringify(audits));
15-
});
16-
});
26+
} catch (error) {
27+
console.error('Error fetching ticket audits:', error);
28+
}
29+
}
30+
31+
listTicketAudits();

examples/users-listbygroup.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ const client = zd.createClient({
88
remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
99
});
1010

11-
client.groups
12-
.list()
13-
.then(function (result) {
14-
client.users.listByGroup(result[0].id).then(function (users) {
15-
console.log(users);
16-
});
17-
})
18-
.catch(function (error) {
19-
console.log(error);
20-
});
11+
/**
12+
*
13+
*/
14+
async function listUsersByFirstGroup() {
15+
try {
16+
const groups = await client.groups.list();
17+
const firstGroup = groups[0];
18+
19+
if (!firstGroup) {
20+
console.log('No groups found.');
21+
return;
22+
}
23+
24+
const users = await client.users.listByGroup(firstGroup.id);
25+
console.log(users);
26+
} catch (error) {
27+
console.error(error);
28+
}
29+
}
30+
31+
listUsersByFirstGroup();

examples/usertags-list.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ const client = zd.createClient({
88
remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
99
});
1010

11-
client.users
12-
.list()
13-
.then(function (result) {
14-
client.users.listTags(result[0].id).then(function (tags) {
15-
console.log(tags);
16-
});
17-
})
18-
.catch(function (error) {
19-
console.log(error);
20-
});
11+
/**
12+
*
13+
*/
14+
async function listTagsForFirstUser() {
15+
try {
16+
const users = await client.users.list();
17+
const firstUser = users[0];
18+
19+
if (!firstUser) {
20+
console.log('No users found.');
21+
return;
22+
}
23+
24+
const tags = await client.users.listTags(firstUser.id);
25+
console.log(tags);
26+
} catch (error) {
27+
console.error(error);
28+
}
29+
}
30+
31+
listTagsForFirstUser();

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@
157157
"nock": "^13.5.0",
158158
"typedoc": "^0.26.5",
159159
"typedoc-plugin-markdown": "^4.2.3",
160-
"vitepress": "1.3.1",
161-
"vitepress-sidebar": "1.24.1",
160+
"vitepress": "^1.3.1",
161+
"vitepress-sidebar": "^1.24.1",
162162
"vitest": "^1.2.1",
163163
"vue-github-button": "^3.1.0",
164-
"xo": "^0.56.0"
164+
"xo": "^0.59.3"
165165
}
166166
}

src/clients/client.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ class Client {
121121

122122
/**
123123
* Patches a resource.
124-
* @param {...any} args - The resources or parts of the resource path followed by the body.
124+
* @param {...any} arguments_ - The resources or parts of the resource path followed by the body.
125125
* @returns {Promise<void|object>} - Either void or response object
126126
*/
127-
async patch(...args) {
128-
const body = args.pop();
129-
const resource = Array.isArray(args[0]) ? args[0] : args;
127+
async patch(...arguments_) {
128+
const body = arguments_.pop();
129+
const resource = Array.isArray(arguments_[0]) ? arguments_[0] : arguments_;
130130

131131
return this.request('PATCH', resource, body);
132132
}
@@ -141,24 +141,24 @@ class Client {
141141

142142
/**
143143
* Deletes a resource.
144-
* @param {...any} args - The resources or parts of the resource path.
144+
* @param {...any} arguments_ - The resources or parts of the resource path.
145145
* @returns {Promise<void|object>} - Either void or response object
146146
*/
147-
async delete(...args) {
147+
async delete(...arguments_) {
148148
// Check if the first argument is an array
149-
const resource = Array.isArray(args[0]) ? args[0] : args;
149+
const resource = Array.isArray(arguments_[0]) ? arguments_[0] : arguments_;
150150
return this.request('DELETE', resource);
151151
}
152152

153153
async getAll(resource) {
154154
return this.requestAll('GET', resource);
155155
}
156156

157-
async _rawRequest(method, uri, ...args) {
157+
async _rawRequest(method, uri, ...arguments_) {
158158
const body =
159-
typeof args.at(-1) === 'object' &&
160-
!Array.isArray(args.at(-1)) &&
161-
args.pop();
159+
typeof arguments_.at(-1) === 'object' &&
160+
!Array.isArray(arguments_.at(-1)) &&
161+
arguments_.pop();
162162

163163
return this.transporter.request(method, uri, body);
164164
}
@@ -175,12 +175,16 @@ class Client {
175175
* @template T
176176
* @param {string} method - HTTP method (e.g., 'GET', 'POST').
177177
* @param {string} uri - The URI for the request.
178-
* @param {...any} args - Additional arguments for the request.
178+
* @param {...any} arguments_ - Additional arguments for the request.
179179
* @returns {Promise<module:client.ApiResponse<T>>} - The API response.
180180
*/
181-
async request(method, uri, ...args) {
181+
async request(method, uri, ...arguments_) {
182182
try {
183-
const {response, result} = await this._rawRequest(method, uri, ...args);
183+
const {response, result} = await this._rawRequest(
184+
method,
185+
uri,
186+
...arguments_,
187+
);
184188
const responseBody = processResponseBody(
185189
checkRequestResponse(response, result),
186190
this,
@@ -209,7 +213,7 @@ class Client {
209213
}
210214

211215
// Request method for fetching multiple pages of results
212-
async requestAll(method, uri, ...args) {
216+
async requestAll(method, uri, ...arguments_) {
213217
const bodyList = [];
214218
const throttle = this.options.get('throttle');
215219
let __request = this._rawRequest; // Use _rawRequest directly
@@ -238,7 +242,12 @@ class Client {
238242

239243
const fetchPagesRecursively = async (pageUri) => {
240244
const isIncremental = pageUri.includes('incremental');
241-
const responseData = await __request.call(this, method, pageUri, ...args);
245+
const responseData = await __request.call(
246+
this,
247+
method,
248+
pageUri,
249+
...arguments_,
250+
);
242251
const nextPage = processPage(responseData);
243252
if (
244253
nextPage &&

src/clients/core/users.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,22 @@ class Users extends Client {
217217

218218
/**
219219
* Updates multiple users.
220-
* @param {...*} args - Arguments including optional IDs and user details.
220+
* @param {...*} arguments_ - Arguments including optional IDs and user details.
221221
* @returns {Promise<Array<User>>} An array of updated user details.
222222
* @throws {Error} Throws an error if not enough arguments are provided.
223223
* @see {@link https://developer.zendesk.com/api-reference/ticketing/users/users/#update-many-users}
224224
* @example
225225
* const updatedUsers = await client.users.updateMany([12345, 67890], [{name: 'John Doe'}, {name: 'Jane Smith'}]);
226226
*/
227-
async updateMany(...args /* Optional ids, users, cb */) {
228-
if (args.length < 2) {
227+
async updateMany(...arguments_ /* Optional ids, users, cb */) {
228+
if (arguments_.length < 2) {
229229
throw new Error('Not enough arguments; at least two expected.');
230230
}
231231

232-
const ids = args[0];
233-
const users = args.length === 2 ? args[0] : args[1];
232+
const ids = arguments_[0];
233+
const users = arguments_.length === 2 ? arguments_[0] : arguments_[1];
234234

235-
if (args.length === 2) {
235+
if (arguments_.length === 2) {
236236
return this.put(['users', 'update_many'], users);
237237
}
238238

@@ -314,22 +314,22 @@ class Users extends Client {
314314

315315
/**
316316
* Deletes multiple users.
317-
* @param {...*} args - Arguments including optional IDs and user details.
317+
* @param {...any} arguments_ - Arguments including optional IDs and user details.
318318
* @returns {Promise<void>}
319319
* @throws {Error} Throws an error if not enough arguments are provided.
320320
* @see {@link https://developer.zendesk.com/api-reference/ticketing/users/users/#delete-many-users}
321321
* @example
322322
* await client.users.destroyMany([12345, 67890]);
323323
*/
324-
async destroyMany(...args) {
325-
if (args.length < 2) {
324+
async destroyMany(...arguments_) {
325+
if (arguments_.length < 2) {
326326
throw new Error('Not enough arguments; at least two expected.');
327327
}
328328

329-
const ids = args[0];
330-
const users = args.length === 2 ? args[0] : args[1];
329+
const ids = arguments_[0];
330+
const users = arguments_.length === 2 ? arguments_[0] : arguments_[1];
331331

332-
if (args.length === 2) {
332+
if (arguments_.length === 2) {
333333
return super.delete(['users', 'destroy_many'], users);
334334
}
335335

src/clients/helpers.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const failCodes = {
2020
function flatten(array) {
2121
// eslint-disable-next-line unicorn/no-array-reduce
2222
return array.reduce(
23-
(acc, element) =>
23+
(accumulator, element) =>
2424
// eslint-disable-next-line unicorn/prefer-spread
25-
acc.concat(Array.isArray(element) ? flatten(element) : element),
25+
accumulator.concat(Array.isArray(element) ? flatten(element) : element),
2626
[],
2727
);
2828
}
@@ -45,7 +45,7 @@ function populateFields(data, response, map) {
4545

4646
const populateRecord = (record) => {
4747
for (const {field, name, dataset, all, dataKey, array} of map) {
48-
if (Object.hasOwnProperty.call(record, field)) {
48+
if (Object.hasOwn(record, field)) {
4949
const responseDataset = datasetCache.get(dataset) || response[dataset];
5050
datasetCache.set(dataset, responseDataset);
5151

@@ -281,7 +281,7 @@ function findBody(result_, self) {
281281

282282
if (self.jsonAPINames) {
283283
const apiName = self.jsonAPINames.find((api) =>
284-
Object.hasOwnProperty.call(result_, api),
284+
Object.hasOwn(result_, api),
285285
);
286286
if (apiName) {
287287
return result_[apiName];

src/clients/throttle.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = throttle;
44
* Creates a throttled function that limits the rate of execution of the provided function.
55
* The throttled function ensures that the wrapped function is not invoked more frequently
66
* than a specified time interval.
7-
* @param {...any} args - The arguments for the throttled function. This can include:
7+
* @param {...any} arguments_ - The arguments for the throttled function. This can include:
88
* - `fn` (Function): The function to be throttled.
99
* - `options` (object, optional): Throttling options.
1010
* - `options.interval` (number|string, optional): The time interval in milliseconds between function calls.
@@ -24,8 +24,9 @@ module.exports = throttle;
2424
*
2525
* Credit: Original inspiration from https://github.com/brianloveswords/throttle-function "Brian J Brennan" <[email protected]>
2626
*/
27-
function throttle(...args) {
28-
const [thisArg, fn, options = {}] = args.length > 1 ? args : [null, ...args];
27+
function throttle(...arguments_) {
28+
const [thisArgument, function_, options = {}] =
29+
arguments_.length > 1 ? arguments_ : [null, ...arguments_];
2930
const msBetweenCalls = getMsBetweenCalls(options);
3031
const queue = [];
3132
let timer;
@@ -47,12 +48,12 @@ function throttle(...args) {
4748
*/
4849
function runQueue() {
4950
if (queue.length === 0) clearInterval(timer);
50-
return queue.shift() ? fn.apply(thisArg, queue.shift()) : null;
51+
return queue.shift() ? function_.apply(thisArgument, queue.shift()) : null;
5152
}
5253

53-
return function (...args) {
54-
queue.push(args);
55-
if (!timer) timer = setInterval(runQueue, msBetweenCalls);
54+
return function (...arguments_) {
55+
queue.push(arguments_);
56+
timer ||= setInterval(runQueue, msBetweenCalls);
5657

5758
return {
5859
position: queue.length,

0 commit comments

Comments
 (0)