The Management Client SDK does not provide enough type safety

Open
#1,295 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
node.js, typescript

Research direction

Start by reproducing the two TypeScript examples against the Management Client SDK. Review src/management/api/types/types.ts, including the referenced broad index signatures, and trace the return types for users.list and jobs.usersExports.create. Done means invalid response properties are rejected by the TypeScript compiler without weakening valid API fields.

Written by the indexing model from the issue text.

Description

bug
Checklist
  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.
Description

When upgrading existing code to the latest SDK (5.x) version there were multiple occasions where I was referencing incorrect fields, but the typescript compiler did not complain because the return types have very broad type definitions:

/** Accepts any additional properties */
[key: string]: any;

One example: https://github.com/auth0/node-auth0/blob/6a0be4bb06864bd911bb7438dc80556b3092dd4f/src/management/api/types/types.ts#L20656-L20657

The correct definitions should be tight enough that when there are changes to the API, the developer will know from the typescript compiler alone that their code is referencing properties which do not exist.

Reproduction
  1. Create a query e.g.
// EXAMPLE 1
const { data } = await auth0Client.users.list()
const val = data[0].invalidPropertyThatDoesNotComplain

// EXAMPLE 2
const exportJobInfo = await auth0Client.jobs.usersExports.create({
  connection_id: process.env.AUTH_CONNECTION_ID,
  format: 'json'
})
const exportJobId = exportJobInfo.invalidPropertyThatDoesNotComplain.id
  1. Observe as the typescript compiler does not indicate that the fields are not valid
Additional context

No response

node-auth0 version

5.3.0

Node.js version

v22.22.0

Dominant language
TypeScript
Stars
683
Forks
319
Avg merge
1d 30m
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/node-auth0

All issues in auth0/node-auth0

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.