Skip to content

feat(oauth): add comprehensive TypeScript types and eliminate all 'any' usage - #2021

Merged
ArtieReus merged 16 commits into
mainfrom
artie-oauth-switch-typescript
Sep 29, 2026
Merged

ArtieReus merged 16 commits into
mainfrom
artie-oauth-switch-typescript

Conversation

@ArtieReus

@ArtieReus ArtieReus commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive TypeScript types throughout the OAuth package and eliminates all 44 occurrences of any type. This establishes a strong type foundation for the package and prepares it for ESLint config

Changes Made

  • Created src/types.ts: Centralized all shared type definitions

    • FlowType, OidcConfig, IdTokenData, ParsedTokenData, AuthData
    • SessionState discriminated union for type-safe state management
    • TokenSessionState for tokenSession's simpler state model
    • OidcStateData, TokenResponse, FlowResponse for OAuth flows
    • All session parameter and instance interfaces
  • src/utils.ts: Typed all utility functions (encodeBase64Json, decodeBase64Json, paramsToUrl)

  • src/tokenHelpers.ts: Added proper return types and fixed array map callbacks

  • src/oidcConfig.ts: Fixed async bug (config: await r.json()) and added types

  • src/oidcState.ts: Typed state management and PKCE callbacks

  • src/implicitFlow.ts & src/codeFlow.ts: Typed all OAuth flow functions

  • src/oidcSession.ts: Most comprehensive changes

    • Created SessionStateUpdate union type for type-safe partial updates
    • Enforces discriminated union constraints at compile time
    • Refactored receiveNewData to explicitly handle auth data presence
    • Added comments explaining discriminated union type narrowing
    • Used ES6 shorthand syntax (flowType instead of flowType: flowType)
  • src/tokenSession.ts: Aligned with shared types from types.ts

  • src/mockedSession.ts: Uses shared SessionState and interfaces

  • src/index.ts: Exported all public types for consumers including TokenSessionState

Related Issues

Screenshots (if applicable)

N/A - Type-only changes, no visual impact

Testing Instructions

  1. pnpm i
  2. cd packages/oauth
  3. pnpm typecheck - should pass with no errors
  4. pnpm lint - should pass with no errors
  5. pnpm test - all 85 tests should pass
  6. pnpm build - should build successfully

Checklist

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have made corresponding changes to the documentation (if applicable).
  • My changes generate no new warnings or errors.
  • I have created a changeset for my changes.

PR Manifesto

Review the PR Manifesto for best practises.

Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 12:16
@ArtieReus
ArtieReus requested a review from a team as a code owner September 29, 2026 12:16
@changeset-bot

changeset-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f232669

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Public contracts remain disconnected or inaccurate, and decoded OAuth data is asserted without adequate runtime validation.

Review effort: Balanced
Findings: 1 High severity · 5 Medium severity

Open (6)
What changed in this PR

Introduces centralized OAuth types and strengthens TypeScript coverage across session, token, state, and flow utilities.

Changes:

  • Adds and exports shared OAuth models and session contracts.
  • Replaces several any usages with explicit types.
  • Updates flow tests with required OIDC state fields.
File Description
packages/​oauth/​src/​types.ts Adds shared OAuth types.
packages/​oauth/​src/​index.ts Exports public types.
packages/​oauth/​src/​utils.ts Types encoding and URL helpers.
packages/​oauth/​src/​tokenSession.ts Types token composition data.
packages/​oauth/​src/​tokenHelpers.ts Types token decoding and parsing.
packages/​oauth/​src/​oidcState.ts Types persisted OIDC state and PKCE.
packages/​oauth/​src/​oidcConfig.ts Types discovery configuration and cache.
packages/​oauth/​src/​implicitFlow.ts Types implicit-flow inputs and results.
packages/​oauth/​src/​codeFlow.ts Types code-flow inputs and results.
packages/​oauth/​__tests__/​implicitFlow.test.ts Updates typed state fixture.
packages/​oauth/​__tests__/​codeFlow.test.ts Updates typed state fixtures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/oauth/src/oidcState.ts Outdated
Comment thread packages/oauth/src/index.ts
Comment thread packages/oauth/src/tokenHelpers.ts Outdated
Comment thread packages/oauth/src/types.ts Outdated
Comment thread packages/oauth/src/types.ts Outdated
Comment thread packages/oauth/src/types.ts Outdated
…e safety

Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
@ArtieReus ArtieReus changed the title feat(oauth): convert package to use correct types feat(oauth): add comprehensive TypeScript types and eliminate all 'any' usage Sep 29, 2026
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Custom callback URLs can break code-flow login, and mock-token handling has input and encoding regressions.

Review effort: Balanced
Findings: 2 High severity · 2 Medium severity

Open (4)
Resolved since last review (6)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Allow numeric and boolean OIDC request parameters

packages/​oauth/​src/​types.ts:268

requestParams now rejects numeric and boolean values such as { max_age: 0 }, although createOidcRequest stringifies each value when building the URL and earlier callers could pass them. Widen this field and the matching CreateOidcRequestParams.requestParams to accept string | number | boolean values so existing, working requests still type-check.

Comment thread packages/oauth/src/mockedSession.ts Outdated
Comment thread packages/oauth/src/oidcSession.ts
Comment thread packages/oauth/src/mockedSession.ts Outdated
Comment thread packages/oauth/src/tokenHelpers.ts
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
@ArtieReus
ArtieReus requested a balanced review from Copilot September 29, 2026 14:41
@ArtieReus ArtieReus added the greenhouse-pr-build Set this label to create a preview image which will automatically set the `greenhouse-pr-preview` label Sep 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Reusing a URL input can fetch the wrong discovery path, and the stated removal of explicit any is incomplete.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (4)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Clone URL before appending the OIDC discovery path

packages/​oauth/​src/​oidcConfig.ts:11

getOidcConfig now explicitly accepts a URL, but line 23 uses that same object and line 26 appends the discovery path to its pathname. After one call, the caller's URL is changed; calling again with it misses the original cache entry and fetches a path with /.well-known/openid-configuration appended twice. Clone the URL before changing its pathname and cover reuse of a URL instance in the config tests.

Low severity Remove any cast and type-check the PKCE callback

packages/​oauth/​src/​oidcState.ts:15

The new PKCE callback type does not remove the (getPkceImport as any) cast on line 12, so this source file still contains an explicit any despite the PR's stated goal. That cast also bypasses checking the resolved callable. Narrow the CommonJS/ESM export from unknown, verify it is a function, and give that function the PKCE signature.

Comment thread packages/oauth/src/codeFlow.ts
@github-actions github-actions Bot added the greenhouse-pr-preview THIS LABEL IS SET AUTOMATICALLY. label Sep 29, 2026
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
@github-actions github-actions Bot added greenhouse-pr-preview THIS LABEL IS SET AUTOMATICALLY. and removed greenhouse-pr-preview THIS LABEL IS SET AUTOMATICALLY. labels Sep 29, 2026
@ArtieReus
ArtieReus merged commit 36c3211 into main Sep 29, 2026
24 checks passed
@ArtieReus
ArtieReus deleted the artie-oauth-switch-typescript branch September 29, 2026 16:31
@github-actions github-actions Bot removed the greenhouse-pr-preview THIS LABEL IS SET AUTOMATICALLY. label Sep 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-29 16:32 UTC

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

Labels

greenhouse-pr-build Set this label to create a preview image which will automatically set the `greenhouse-pr-preview`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants