blakmatrix / node-zendesk

A trusted Zendesk API client library for Node.js and the browser, lovingly maintained for over 10 years.

Home Page:https://blakmatrix.github.io/node-zendesk/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mismatched types

zomchak-code opened this issue · comments

Describe the Bug
Types are not matching actual values returned

Example Code

const ticket = await client.tickets.show(392005);
console.log({ id: ticket.id, response: ticket.response });

Screenshot 2023-12-15 at 00 26 43

Expected Behavior
Either .id reported as type error or following output:

{
  id: 392005,
  response: undefined
}

Actual Behavior
Either .resource reported as type error and following output:

{
  id: undefined,
  response: {
    json: [Function: json],
    status: 200,
    headers: {
      get: [Function: get]
    },
    statusText: "OK"
  }
}

Environment Information

  • node-zendesk version: 5.0.7
  • Node.js version: 20.2.0
  • Operating System: MacOS
  • Any other relevant software versions?

I'm seeing something similar with the TS types. I'm making a users.createOrUpdate call. The types say it returns a Promise<User>. But when the promise resolves, I don't have a User, I have a wrapper object with response and result properties. result is of type User.

Paste of the method declaration in 5.0.9 from my node_modules:

    /**
     * Creates or updates a user.
     * @param {object} user - The user details.
     * @returns {Promise<User>} The created or updated user's details.
     * @async
     * @see {@link https://developer.zendesk.com/api-reference/ticketing/users/users/#create-or-update-user}
     * @example
     * const user = await client.users.createOrUpdate({name: 'John Doe', email: 'john@example.com'});
     */
    createOrUpdate(user: object): Promise<User>;

And the original JS declaration in the repo:

/**
* Creates or updates a user.
* @param {object} user - The user details.
* @returns {Promise<User>} The created or updated user's details.
* @async
* @see {@link https://developer.zendesk.com/api-reference/ticketing/users/users/#create-or-update-user}
* @example
* const user = await client.users.createOrUpdate({name: 'John Doe', email: 'john@example.com'});
*/
async createOrUpdate(user) {
return this.post(['users', 'create_or_update'], user);
}

Paste of the actual resolved value:

{
  response: {
    json: [Function: json],
    status: 201,
    headers: { get: [Function: get] },
    statusText: 'Created'
  },
  result: {
    id: ...,
    ... other User properties ...
  }
}

I have the same issue with users.show where it expects to return a Promise<User> but the actual response value is Promise<{result: User}>

I just contributed to the bounty on this issue.

Each contribution to this bounty has an expiry time and will be auto-refunded to the contributor if the issue is not solved before then.

Current bounty reward

To make this a public bounty or have a reward split, the maintainer can reply to this comment.

ditto — exactly what @mackstann is seeing returned is also returning for me when using users.update