Skip to content

fix(types): OAuthError.inner, saveToken input, and getClient clientSecret#444

Merged
jankapunkt merged 3 commits into
node-oauth:masterfrom
dhensby:fix/types-savetoken-oautherror
Jun 16, 2026
Merged

fix(types): OAuthError.inner, saveToken input, and getClient clientSecret#444
jankapunkt merged 3 commits into
node-oauth:masterfrom
dhensby:fix/types-savetoken-oautherror

Conversation

@dhensby

@dhensby dhensby commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What

Three index.d.ts typing corrections.

Closes #367. Closes #368.

Changes

fix(types): add missing OAuthError.inner property (#367)

OAuthError sets this.inner to the wrapped error when constructed from another Error (oauth-error.js), and the handlers do exactly that (new ServerError(e)), but the property was missing from the published typings. Added inner?: Error. Thanks @papermana for the report.

Note: @wille suggested exposing the wrapped error via the standard Error.cause instead. That's a good idea, but it's a runtime change — this PR just documents the property that already exists. Adopting .cause (keeping .inner as a deprecated alias) would be a sensible follow-up.

fix(types): correct saveToken input to exclude client/user (#368)

The grant types call model.saveToken() with a token object that does not include client/user — they're passed as separate arguments and must be present on the returned value (TokenModel requires them). Typing the input as the full Token let saveToken(token) { return token } type-check while throwing at runtime. Narrowed the input to Omit<Token, 'client' | 'user'>. Thanks @papermana.

fix(types): allow getClient clientSecret to be omitted

The token handler calls model.getClient() with no client secret for public / PKCE clients (clientSecret is undefined), and the docs describe it as nullable, but the typing required a string. Made it optional (clientSecret?: string). This addresses the secondary typing point raised by @Valerionn in #281's thread.

Notes

  • Verified index.d.ts still compiles cleanly (tsc --noEmit --strict).
  • The saveToken change is a type-only tightening: it can surface (correct) compile errors in consumer code that relied on the old, inaccurate type. No runtime change — but you may prefer to release it in a minor rather than a patch.

🤖 Generated with Claude Code

dhensby and others added 3 commits June 16, 2026 10:04
OAuthError sets `this.inner` to the wrapped error when constructed from
another Error (lib/errors/oauth-error.js), but the property was absent
from the published typings. Add `inner?: Error` so consumers can read it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The grant types call model.saveToken() with a token object that does not
include `client`/`user` — those are passed as separate arguments and must
be present on the returned value. Typing the input as the full `Token`
allowed `saveToken(token) { return token }` to type-check while throwing at
runtime. Narrow the input to `Omit<Token, 'client' | 'user'>`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The token handler calls model.getClient() with no client secret for
public / PKCE clients (clientSecret is `undefined`), and the docs describe
it as nullable, but the typing required a `string`. Make it optional
(`clientSecret?: string`).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dhensby dhensby changed the title fix(types): add OAuthError.inner and correct saveToken input typing fix(types): OAuthError.inner, saveToken input, and getClient clientSecret Jun 16, 2026
@jankapunkt jankapunkt merged commit 17d9230 into node-oauth:master Jun 16, 2026
4 checks passed
@jankapunkt

Copy link
Copy Markdown
Member

Due to the recommendation of a minor release I am about to create an RC for this. Any objections @dhensby ?

@dhensby dhensby deleted the fix/types-savetoken-oautherror branch June 16, 2026 10:39
@dhensby

dhensby commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Due to the recommendation of a minor release I am about to create an RC for this. Any objections @dhensby ?

Maybe wait for a few more PRs to land 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

saveToken has incorrect type signature Property inner missing from OAuthError typings

2 participants