Skip to content

[CDX-390] Update VariationsMap#225

Merged
esezen merged 7 commits intomainfrom
cdx-390-client-js-update-type-definitions-for-variationsmap-2
Apr 15, 2026
Merged

[CDX-390] Update VariationsMap#225
esezen merged 7 commits intomainfrom
cdx-390-client-js-update-type-definitions-for-variationsmap-2

Conversation

@esezen
Copy link
Copy Markdown
Contributor

@esezen esezen commented Mar 24, 2026

Updated client-js to the latest. Since fetch-ponyfill got removed from client-js I had to bring in whatwg-fetch as a devDependency similar to how we do it in AC UI library

Copilot AI review requested due to automatic review settings March 24, 2026 15:18
constructor-claude-bedrock[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates this UI library to work with the latest @constructor-io/constructorio-client-javascript, including type updates and test/runtime fetch polyfilling to replace the removed fetch-ponyfill.

Changes:

  • Bumped @constructor-io/constructorio-client-javascript peer dependency to ^2.77.0.
  • Updated types to reflect new client-js typings (VariationsMapResponse, RangeMin/RangeMax, BaseGroup support).
  • Added whatwg-fetch and configured Jest to polyfill fetch in the jsdom test project.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/transformers.ts Expands group transformer input typing to accept BaseGroup in addition to Group.
src/types.ts Aligns public types with updated client-js (VariationsMapResponse, RangeMin/RangeMax).
spec/hooks/useCioClient/useCioClient.test.js Updates test to use a functional fetch mock and relaxes options assertion.
jest.config.js Loads whatwg-fetch for client (jsdom) Jest runs.
package.json Bumps client-js peer dependency and adds whatwg-fetch devDependency.
package-lock.json Lockfile updates reflecting dependency bump and new devDependency.
Comments suppressed due to low confidence (1)

package.json:65

  • With the bump to @constructor-io/constructorio-client-javascript ^2.77.0, the client options fetch value is now likely expected to be a function (as reflected in the updated useCioClient test). There are still tests passing fetch: 'mock-fetch-fn' (e.g. spec/hooks/useCioPlpProvider/useCioPlpProvider.test.js and related server tests), which may start failing at runtime if the new client validates option types. Update those mocks to use a function (e.g. jest.fn()) or omit fetch where it’s not needed.
  "peerDependencies": {
    "@constructor-io/constructorio-client-javascript": "^2.77.0",
    "react": ">=16.12.0",
    "react-dom": ">=16.12.0",
    "tslib": "^2.4.0"
  },

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

HHHindawy
HHHindawy previously approved these changes Apr 14, 2026
@esezen esezen force-pushed the cdx-390-client-js-update-type-definitions-for-variationsmap-2 branch from 2b529ff to ec297a9 Compare April 15, 2026 13:50
@esezen esezen requested a review from a team as a code owner April 15, 2026 13:50
@esezen esezen requested a review from HHHindawy April 15, 2026 13:50
constructor-claude-bedrock[bot]

This comment was marked as outdated.

constructor-claude-bedrock[bot]

This comment was marked as outdated.

constructor-claude-bedrock[bot]

This comment was marked as outdated.

constructor-claude-bedrock[bot]

This comment was marked as outdated.

Copy link
Copy Markdown

@constructor-claude-bedrock constructor-claude-bedrock bot left a comment

Choose a reason for hiding this comment

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

Code Review

This PR upgrades constructorio-client-javascript from ^2.35.14 to ^2.77.0 and adapts the codebase to the removal of fetch-ponyfill, while improving type accuracy with VariationsMapResponse, RangeMin/RangeMax, and BaseGroup — overall a clean and necessary update with a few issues worth addressing.

Inline comments: 4 discussions added

Overall Assessment: ⚠️ Needs Work

Comment thread src/types.ts
@@ -9,6 +9,7 @@ import {
SearchResponse,
GetBrowseResultsResponse,
VariationsMap,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important Issue: VariationsMap is still imported and used in RequestConfigs.variationsMap (line 207), so this import is correct and necessary. However, both VariationsMap (request config type) and VariationsMapResponse (response type) now coexist in the imports — consider adding a comment near the RequestConfigs.variationsMap field clarifying the distinction (i.e. VariationsMap is the request shape passed into API calls, while VariationsMapResponse is what comes back in responses). This is subtle and easy to misuse.

Comment thread src/types.ts
itemName: string;
variations?: Variation[];
variationsMap?: VariationsMap;
variationsMap?: VariationsMapResponse;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The Item.variationsMap field is now correctly typed as VariationsMapResponse (the response shape). This is a breaking change for any consumers that typed this field as VariationsMap. A changelog entry or a note in the PR description about the breaking nature of this type change would help downstream teams upgrading.

Comment thread src/utils/transformers.ts
}

export function transformItemGroups(groups?: Group[]): PlpItemGroup[] {
export function transformItemGroups(groups?: (Group | BaseGroup)[]): PlpItemGroup[] {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important Issue: transformItemGroups now accepts BaseGroup in addition to Group, but there are no tests covering this new union type input. The existing test suite has zero coverage for transformItemGroups altogether (confirmed by search). A test covering BaseGroup-typed input (which lacks the children/parents arrays that Group has) should be added to avoid silent runtime failures when the API returns a BaseGroup. Please verify that BaseGroup also has children and parents fields — if it does not, the recursive transformItemGroups(itemGroup.children) call at line 215 would fail at runtime.

segments: ['segment-1', 'segment-2'],
testCells: { test: 'cell' },
fetch: 'mock-fetch-fn',
fetch: jest.fn(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Changing fetch from 'mock-fetch-fn' (a string) to jest.fn() (an actual function) is the correct fix since the new client-js version likely validates the fetch option is callable. The switch to expect.objectContaining(...) is also appropriate because the new client internals may add extra options. However, the spread ...clientOptions inside objectContaining includes fetch: jest.fn(), which will always pass since objectContaining does not perform deep equality on function references — this is fine for the intent of the test, but the assertion on fetch is now effectively untested. If verifying the fetch override behaviour is important, consider a dedicated assertion like expect(client.options.fetch).toBe(clientOptions.fetch).

Copy link
Copy Markdown
Contributor

@HHHindawy HHHindawy left a comment

Choose a reason for hiding this comment

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

LGTM!

@esezen esezen merged commit 852c968 into main Apr 15, 2026
11 of 12 checks passed
@esezen esezen deleted the cdx-390-client-js-update-type-definitions-for-variationsmap-2 branch April 15, 2026 16:06
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.

3 participants