Skip to content

fix(davinci-client): fix collector value types and simplify node reducer imports#637

Open
ancheetah wants to merge 1 commit into
mainfrom
update-davinci-types
Open

fix(davinci-client): fix collector value types and simplify node reducer imports#637
ancheetah wants to merge 1 commit into
mainfrom
update-davinci-types

Conversation

@ancheetah
Copy link
Copy Markdown
Collaborator

@ancheetah ancheetah commented May 19, 2026

JIRA Ticket

Description

client.types.ts

  • Renamed CollectorInputTypesCollectorValueTypes and added DeviceValue to the union.
  • Rewrote CollectorValueType<T> conditional type: grouped branches by return type (string, boolean, string[], specialized, category catch-alls), fixed DeviceAuthenticationCollector to return DeviceValue instead of string, added never for ActionCollector and NoValueCollector, and added a SingleValueAutoCollector catch-all.

node.reducer.ts / client.store.ts

  • Replaced ~30 individual collector type imports with Collectors (from node.types) and CollectorValueTypes (from client.types), collapsing verbose inline union annotations to single-type references.

updater-narrowing.types.test-d.ts

  • Deleted

API reports

  • Updated to reflect the renamed CollectorInputTypesCollectorValueTypes export.

Summary by CodeRabbit

  • New Features

    • Enhanced type system for device authentication collector values with improved DeviceValue handling.
  • Refactor

    • Consolidated and simplified collector type definitions, reducing verbose type annotations across the codebase.

Review Change Stack

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: eaae82b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@forgerock/davinci-client Patch
@forgerock/device-client Patch
@forgerock/journey-client Patch
@forgerock/oidc-client Patch
@forgerock/protect Patch
@forgerock/sdk-types Patch
@forgerock/sdk-utilities Patch
@forgerock/iframe-manager Patch
@forgerock/sdk-logger Patch
@forgerock/sdk-oidc Patch
@forgerock/sdk-request-middleware Patch
@forgerock/storage Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

This PR refactors the collector value type system by introducing a centralized CollectorValueTypes union that replaces scattered inline type annotations. The CollectorValueType<T> conditional type is rewritten to map collector categories to their output types, including new support for DeviceValue in device authentication collectors. These core changes propagate through the reducer and client store, simplifying public APIs and type signatures throughout the davinci-client package.

Changes

Collector Value Type System Refactoring

Layer / File(s) Summary
Core type system redefinition
packages/davinci-client/src/lib/client.types.ts
Introduces CollectorValueTypes union (including DeviceValue, phone/FIDO input types) and rewrites CollectorValueType<T> conditional to map collector type and category discriminants to their value types, with conditional fallback handling for action and no-value collectors (never).
Type validation and documentation
packages/davinci-client/src/lib/client.types.test-d.ts, .changeset/little-lamps-float.md
Updates type-assertion tests to validate new CollectorValueTypes and conditional mappings, and documents the rename from CollectorInputTypes, new DeviceValue support, and never handling.
Public API surface documentation
packages/davinci-client/api-report/davinci-client.api.md, davinci-client.types.api.md
Auto-generated reports reflect type changes: removes CollectorInputTypes export, adds CollectorValueTypes, updates CollectorValueType<T> branches, simplifies nodeCollectorReducer to use Collectors[], and updates updateCollectorValues payload to use CollectorValueTypes.
Reducer state and action integration
packages/davinci-client/src/lib/node.reducer.ts
Imports and uses CollectorValueTypes and Collectors[] type aliases; simplifies updateCollectorValues action payload (value: CollectorValueTypes) and initialCollectorValues state typing from explicit union arrays.
Client store API integration
packages/davinci-client/src/lib/client.store.ts
Updates imports to use CollectorValueTypes and collector type aliases; simplifies the update method's returned updater callback signature so its value parameter is typed as CollectorValueTypes.
Configuration and housekeeping
.gitignore
Adds .polaris/ directory to .gitignore.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • cerebrl
  • ryanbas21
  • vatsalparikh

🐰 Types now align in harmony true,
No more scattered unions in the queue,
DeviceValue dances, collectors unite,
Simpler store and reducer, oh what a sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: fixing collector value types and simplifying node reducer imports, which directly match the changeset's primary objectives.
Description check ✅ Passed The description is well-organized with detailed subsections covering all major changes (client.types.ts, node.reducer.ts/client.store.ts, deleted test file, API reports), addressing the template's descriptive requirement despite the JIRA ticket section being empty.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update-davinci-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 19, 2026

View your CI Pipeline Execution ↗ for commit eaae82b

Command Status Duration Result
nx run-many -t build --no-agents ✅ Succeeded <1s View ↗
nx affected -t build lint test typecheck e2e-ci ✅ Succeeded 6m 53s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-19 22:45:05 UTC

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/little-lamps-float.md:
- Around line 1-3: The changeset currently marks '`@forgerock/davinci-client`' as
'patch' but you renamed a public TypeScript export from CollectorInputTypes to
CollectorValueTypes which is a breaking API change; update the changeset entry
to use a breaking bump (change the release type from 'patch' to 'major' for
'`@forgerock/davinci-client`') and include a short note in the changeset text
explaining the exported type rename (mention CollectorInputTypes →
CollectorValueTypes) so release tooling and consumers are aware it's a breaking
change.

In `@packages/davinci-client/src/lib/node.reducer.ts`:
- Around line 52-55: The reducer handling the DeviceAuthenticationCollector must
handle action payloads where action.payload.value can be a DeviceValue object
instead of a string; currently DeviceAuthenticationCollector still compares
option.value (a string) directly to action.payload.value which throws when value
is an object. Update the DeviceAuthenticationCollector reducer (the branch that
processes updateCollectorValues) to normalize the incoming value: if typeof
action.payload.value === 'object' (a DeviceValue), use its id (e.g.
action.payload.value.id) to find the matching option, otherwise use the string
value; then proceed with the existing update logic. Ensure you reference
updateCollectorValues and option.value in your change so valid DeviceValue
payloads resolve by id rather than failing the direct comparison.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a91301c6-6773-4427-b0aa-ef1c2ae1d581

📥 Commits

Reviewing files that changed from the base of the PR and between 9f93d5e and eaae82b.

📒 Files selected for processing (9)
  • .changeset/little-lamps-float.md
  • .gitignore
  • packages/davinci-client/api-report/davinci-client.api.md
  • packages/davinci-client/api-report/davinci-client.types.api.md
  • packages/davinci-client/src/lib/client.store.ts
  • packages/davinci-client/src/lib/client.types.test-d.ts
  • packages/davinci-client/src/lib/client.types.ts
  • packages/davinci-client/src/lib/node.reducer.ts
  • packages/davinci-client/src/lib/updater-narrowing.types.test-d.ts
💤 Files with no reviewable changes (1)
  • packages/davinci-client/src/lib/updater-narrowing.types.test-d.ts

Comment on lines +1 to +3
---
'@forgerock/davinci-client': patch
---
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use a breaking-change bump for this release.

Line 2 sets this as a patch, but this PR removes/renames a public exported type (CollectorInputTypesCollectorValueTypes). That is a compile-time breaking API change for TypeScript consumers.

Suggested changeset fix
 ---
-'`@forgerock/davinci-client`': patch
+'`@forgerock/davinci-client`': major
 ---
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
---
'@forgerock/davinci-client': patch
---
---
'`@forgerock/davinci-client`': major
---
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.changeset/little-lamps-float.md around lines 1 - 3, The changeset currently
marks '`@forgerock/davinci-client`' as 'patch' but you renamed a public TypeScript
export from CollectorInputTypes to CollectorValueTypes which is a breaking API
change; update the changeset entry to use a breaking bump (change the release
type from 'patch' to 'major' for '`@forgerock/davinci-client`') and include a
short note in the changeset text explaining the exported type rename (mention
CollectorInputTypes → CollectorValueTypes) so release tooling and consumers are
aware it's a breaking change.

Comment on lines 52 to 55
export const updateCollectorValues = createAction<{
id: string;
value:
| string
| string[]
| boolean
| PhoneNumberInputValue
| PhoneNumberExtensionInputValue
| FidoRegistrationInputValue
| FidoAuthenticationInputValue;
value: CollectorValueTypes;
index?: number;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Device-auth updater now rejects valid DeviceValue payloads.

Line 54 now allows DeviceValue, but the DeviceAuthenticationCollector reducer path still compares option.value (string) to action.payload.value directly. When update() is narrowed to DeviceValue, that comparison fails and throws “No option found matching value to update” for valid inputs.

Suggested reducer fix (accept `DeviceValue` and resolve by id)
       if (collector.type === 'DeviceAuthenticationCollector') {
-        if (typeof action.payload.id !== 'string') {
-          throw new Error('Index argument must be a string');
-        }
-        // Iterate through the options object and find option to update
-        const option = collector.output.options.find(
-          (option) => option.value === action.payload.value,
-        );
+        const selectedId =
+          typeof action.payload.value === 'string'
+            ? action.payload.value
+            : typeof action.payload.value === 'object' &&
+                action.payload.value !== null &&
+                'id' in action.payload.value &&
+                typeof action.payload.value.id === 'string'
+              ? action.payload.value.id
+              : null;
+
+        if (!selectedId) {
+          throw new Error('Value argument must be a valid device selection');
+        }
+
+        const option = collector.output.options.find((option) => option.value === selectedId);
 
         if (!option) {
           throw new Error('No option found matching value to update');
         }
 
         // Remap values back to DaVinci spec
         collector.input.value = {
           type: option.type,
           id: option.value,
           value: option.content,
         };
+        return;
       }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/davinci-client/src/lib/node.reducer.ts` around lines 52 - 55, The
reducer handling the DeviceAuthenticationCollector must handle action payloads
where action.payload.value can be a DeviceValue object instead of a string;
currently DeviceAuthenticationCollector still compares option.value (a string)
directly to action.payload.value which throws when value is an object. Update
the DeviceAuthenticationCollector reducer (the branch that processes
updateCollectorValues) to normalize the incoming value: if typeof
action.payload.value === 'object' (a DeviceValue), use its id (e.g.
action.payload.value.id) to find the matching option, otherwise use the string
value; then proceed with the existing update logic. Ensure you reference
updateCollectorValues and option.value in your change so valid DeviceValue
payloads resolve by id rather than failing the direct comparison.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

@forgerock/davinci-client

pnpm add https://pkg.pr.new/@forgerock/davinci-client@637

@forgerock/device-client

pnpm add https://pkg.pr.new/@forgerock/device-client@637

@forgerock/journey-client

pnpm add https://pkg.pr.new/@forgerock/journey-client@637

@forgerock/oidc-client

pnpm add https://pkg.pr.new/@forgerock/oidc-client@637

@forgerock/protect

pnpm add https://pkg.pr.new/@forgerock/protect@637

@forgerock/sdk-types

pnpm add https://pkg.pr.new/@forgerock/sdk-types@637

@forgerock/sdk-utilities

pnpm add https://pkg.pr.new/@forgerock/sdk-utilities@637

@forgerock/iframe-manager

pnpm add https://pkg.pr.new/@forgerock/iframe-manager@637

@forgerock/sdk-logger

pnpm add https://pkg.pr.new/@forgerock/sdk-logger@637

@forgerock/sdk-oidc

pnpm add https://pkg.pr.new/@forgerock/sdk-oidc@637

@forgerock/sdk-request-middleware

pnpm add https://pkg.pr.new/@forgerock/sdk-request-middleware@637

@forgerock/storage

pnpm add https://pkg.pr.new/@forgerock/storage@637

commit: eaae82b

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 18.21%. Comparing base (eafe277) to head (eaae82b).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
packages/davinci-client/src/lib/client.store.ts 0.00% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (18.21%) is below the target coverage (40.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #637      +/-   ##
==========================================
+ Coverage   18.07%   18.21%   +0.13%     
==========================================
  Files         155      155              
  Lines       24398    24436      +38     
  Branches     1203     1212       +9     
==========================================
+ Hits         4410     4450      +40     
+ Misses      19988    19986       -2     
Files with missing lines Coverage Δ
packages/davinci-client/src/lib/client.types.ts 100.00% <ø> (ø)
packages/davinci-client/src/lib/node.reducer.ts 71.18% <100.00%> (+0.70%) ⬆️
packages/davinci-client/src/lib/client.store.ts 0.28% <0.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

Deployed 3f02cf4 to https://ForgeRock.github.io/ping-javascript-sdk/pr-637/3f02cf485c45bfff8156ab2504f07724e00f65ea branch gh-pages in ForgeRock/ping-javascript-sdk

@github-actions
Copy link
Copy Markdown
Contributor

📦 Bundle Size Analysis

📦 Bundle Size Analysis

🚨 Significant Changes

🔻 @forgerock/device-client - 0.0 KB (-10.0 KB, -100.0%)
🔻 @forgerock/journey-client - 0.0 KB (-91.9 KB, -100.0%)

📊 Minor Changes

📉 @forgerock/davinci-client - 53.9 KB (-0.3 KB)

➖ No Changes

@forgerock/storage - 1.5 KB
@forgerock/sdk-request-middleware - 4.5 KB
@forgerock/iframe-manager - 2.4 KB
@forgerock/sdk-oidc - 4.8 KB
@forgerock/sdk-logger - 1.6 KB
@forgerock/sdk-types - 7.9 KB
@forgerock/protect - 144.6 KB
@forgerock/device-client - 10.0 KB
@forgerock/sdk-utilities - 11.2 KB
@forgerock/oidc-client - 25.2 KB
@forgerock/journey-client - 91.9 KB


14 packages analyzed • Baseline from latest main build

Legend

🆕 New package
🔺 Size increased
🔻 Size decreased
➖ No change

ℹ️ How bundle sizes are calculated
  • Current Size: Total gzipped size of all files in the package's dist directory
  • Baseline: Comparison against the latest build from the main branch
  • Files included: All build outputs except source maps and TypeScript build cache
  • Exclusions: .map, .tsbuildinfo, and .d.ts.map files

🔄 Updated automatically on each push to this PR

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants