Skip to content

feat(api): expose product clusters on product groups - #3499

Merged
eduardoformiga merged 3 commits into
devfrom
codex/expose-product-clusters
Sep 29, 2026
Merged

eduardoformiga merged 3 commits into
devfrom
codex/expose-product-clusters

Conversation

@Lucaspoladore

@Lucaspoladore Lucaspoladore commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

VTEX Intelligent Search v1 returns productClusters for each catalog product, and the FastStore VTEX client already receives that data. However, the FastStore GraphQL schema does not expose it, so storefronts cannot read product-cluster membership on PDPs, product cards, or shelves without an API extension or an additional REST request.

This restores access to product cluster IDs and names through the normalized FastStore product model.

How it works

  • Adds StoreProductCluster with id and name.
  • Adds productClusters: [StoreProductCluster!]! to StoreProductGroup, since VTEX product clusters belong to the catalog product rather than an individual SKU.
  • Passes the Intelligent Search response through the StoreProductGroup resolver and returns an empty list when the field is absent.
  • Corrects the Intelligent Search client type from a record to the documented [{ id, name }] response shape.
  • Regenerates API and Core GraphQL types.
  • Adds schema and resolver regression coverage.

Storefront queries can request:

isVariantOf {
  productClusters {
    id
    name
  }
}

This is an additive GraphQL schema change.

How to test it?

  • pnpm --filter @faststore/api test
    • 305 unit tests passed
    • 56 integration tests passed
  • pnpm --filter @faststore/api build
  • pnpm --filter @faststore/core gen-types
  • pnpm exec biome check <changed files>

References

Checklist

  • PR title and commit follow Conventional Commits.
  • Tests and build pass.
  • Generated GraphQL types are included.
  • No dependency or lockfile changes.

Summary by CodeRabbit

  • New Features
    • Product groups now expose product cluster IDs and names through the API, returning an empty list when no clusters are available.
  • Tests
    • Added coverage for product cluster data and its handling when absent.

@Lucaspoladore Lucaspoladore added the contributing Pull request submitted by the community label Sep 24, 2026 — with ChatGPT Codex Connector
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: vtex/faststore/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6bb221fc-dcc5-41a9-a6f3-ae74ef25aebc

📥 Commits

Reviewing files that changed from the base of the PR and between 41b8946 and 3a31c2a.

⛔ Files ignored due to path filters (2)
  • packages/api/src/__generated__/schema.ts is excluded by !**/__generated__/** and included by packages/**
  • packages/core/@generated/graphql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
📒 Files selected for processing (5)
  • packages/api/src/platforms/vtex/clients/search/types/ProductSearchResult.ts
  • packages/api/src/platforms/vtex/resolvers/productGroup.ts
  • packages/api/src/platforms/vtex/typeDefs/productGroup.graphql
  • packages/api/test/integration/schema.test.ts
  • packages/api/test/unit/platforms/vtex/resolvers/productGroup.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


Walkthrough

The VTEX search result model now types product clusters with string id and name fields. StoreProductGroup exposes these clusters through GraphQL, and its resolver returns an empty list when the source value is nullish.

Changes

VTEX product clusters

Layer / File(s) Summary
Product cluster contract
packages/api/src/platforms/vtex/clients/search/types/ProductSearchResult.ts, packages/api/src/platforms/vtex/typeDefs/productGroup.graphql, packages/api/test/integration/schema.test.ts
The search result model and GraphQL schema define product clusters with required string id and name fields. Schema integration tests check the field and object types.
Product group resolver
packages/api/src/platforms/vtex/resolvers/productGroup.ts, packages/api/test/unit/platforms/vtex/resolvers/productGroup.test.ts
The resolver returns isVariantOf.productClusters or [] when the value is omitted. Unit tests cover both cases.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to 3a31c

The change exposes product clusters on product groups with an empty-list fallback when clusters are absent. No concrete merge-blocking issue is established; merge after normal build and test checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 3a31c

The change exposes additional catalog metadata through existing product retrieval, without adding a separate lookup or changing account selection. No control bypass was identified, but the public visibility policy for all returned cluster names and memberships was not independently established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The incremental disclosure surface is product-cluster IDs, names, and membership for products reachable through the existing product resolvers. The new field does not itself create an independent catalog-enumeration or cross-account lookup mechanism.

Trust Boundaries and Controls

  • observed — The VTEX context factory captures platform Options, assigns options.account to the context, and passes those options into client construction. Intelligent Search constructs its destination from the configured account and environment while retaining existing cookie, channel, region, and locale request context. The added cluster resolver introduces no account-selection input.

Hardening Proposals

  • proposed — Document and validate that cluster IDs, names, and memberships returned by Intelligent Search are approved for storefront disclosure. If any cluster categories are private, define an explicit public projection rather than relying on unconditional pass-through.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: exposing product clusters on product groups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4…
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

@codesandbox-ci

codesandbox-ci Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

productClusters: Record<string, string>
clusterHighlights: ProductCluster[]
productClusters: ProductCluster[]
categories: string[]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Interface] 🔴 BLOCK

clusterHighlights and productClusters were retyped from Record<string, string>/Record<string, any> to ProductCluster[], but VTEX's Catalog/Intelligent Search API returns these fields as an id→name map object (e.g. {"140": "Most Wanted"}), not an array of {id, name} objects. The type change does not reflect the real wire shape returned by the platform.

Action: Confirm the actual VTEX Search API response shape for productClusters/clusterHighlights (check a live response or VTEX docs). If it is still a Record<string,string>, keep the map type and transform it explicitly (e.g. Object.entries(raw).map(([id, name]) => ({ id, name }))) at the boundary instead of redeclaring the raw client type as an array.

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/dk-review dismiss Intelligent Search v1 returns productClusters and clusterHighlights as an array of { id, name }, not the Catalog API id-to-name map.

The OpenAPI schema (components.schemas.Product.properties) types both fields as array of { id: string, name: string }. The same shape is already in the FastStore fixtures (packages/api/test/mocks/AllProductsQuery.ts). The previous Record<string, string> type was stale. Catalog's map is a different API: this search client never receives it. Cross-selling only uses Catalog for product IDs, then hydrates the product through productsByIdentifier.

root.isVariantOf.items.map((item) => enhanceSku(item, root.isVariantOf)),
productGroupID: ({ isVariantOf }) => isVariantOf.productId,
productClusters: ({ isVariantOf }) => isVariantOf.productClusters ?? [],
name: (root) => root.isVariantOf.productName,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Check] 🟡 RESTRICT

The productClusters resolver passes isVariantOf.productClusters through unchanged (only defaulting to [] when nullish) and relies on it already matching the GraphQL StoreProductCluster[] shape. If the real VTEX response is an id→name map (as it historically has been for this field) rather than an array, this resolver returns a non-iterable object where GraphQL expects a list, which will throw a serialization error at query time instead of returning data.

Action: Add an explicit transformation step in the resolver that normalizes the raw VTEX payload into StoreProductCluster[] regardless of whether the source is a map or an array, and cover this with a test using a realistic raw fixture.

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/dk-review dismiss The resolver parent is already the Intelligent Search product, so productClusters arrives as { id, name }[]. A map-to-array transform would paper over a contract this client does not have.

isVariantOf.productClusters ?? [] only substitutes an empty list when the field is missing, which matches the non-null GraphQL type [StoreProductCluster!]!. isVariantOf itself is always the enhanced SKU (isVariantOf: (root) => root), so a null-parent case is not a real payload.

@dk-pr-review

dk-pr-review Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

DK Review — Audit Summary

Verdict: ❌ BLOCKED

Severity Count
BLOCK 1
RESTRICT 1
SUGGEST 1

Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other finding below opens no review thread.

Scenarios evaluated: feature-flags, general-review, quality-ratchet
Scenarios skipped: dependency-governance (no matching files), pipeline-config (no matching files), agent-skills-review (no matching files)


📋 Findings (3)

BLOCK

  1. [Functional.Interface] packages/api/src/platforms/vtex/clients/search/types/ProductSearchResult.ts:82 — productClusters was changed from Record<string, string> (an ID→name map, as returned by the VTEX search client) to ProductCluster[] with no parsing/mapping code added anywhere in this diff. The new resolver productGroup.ts (isVariantOf.productClusters ?? []) just passes the raw value straight through, assuming it is already an array of {id, name} objects. If the actual VTEX Intelligent Search payload still comes back as an object map (which is what the prior type declared), GraphQL will fail trying to iterate a non-iterable object for the [StoreProductCluster!]! field, or silently serialize garbage.
    → Confirm the real VTEX Search API response shape for productClusters. If it is still a map, add an explicit Object.entries(...) transformation into {id, name}[] in the client/resolver, and add a unit test that uses the real (map) fixture shape rather than one that already matches the target GraphQL type.

RESTRICT

  1. [Functional.Interface] packages/api/src/platforms/vtex/clients/search/types/ProductSearchResult.ts:81 — clusterHighlights was also retyped from Record<string, any> to ProductCluster[] in the same change, with no accompanying transformation logic and no consumer updated in this diff. This is the same unresolved shape mismatch as productClusters and will surface as a bug for any future/existing consumer of this field once type-checking is relied upon.
    → Either revert this field's type until an actual consumer/transform is implemented, or verify and encode the real search-client response shape before merge.

SUGGEST

  1. [Evolvability.Organizational] packages/api/src/__generated__/schema.ts — This PR directly hand-edits __generated__/schema.ts and packages/core/@generated/graphql.ts. AGENTS.md explicitly lists editing @generated//__generated__/ directories directly as forbidden without explicit human approval, since these are supposed to be produced by the codegen step from productGroup.graphql.
    → Confirm these files were produced by running the project's codegen (pnpm codegen / pnpm build) rather than edited by hand, and note that in the PR description so reviewers can trust they match the schema source of truth.
    Source: AGENTS.md — Agent Autonomy Boundaries

DK Review v1.0.0 | To dismiss a finding: reply /dk-review dismiss [reason] under its comment

Checking only that productClusters exists would still pass if the field type changed.
@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

npm i https://pkg.pr.new/vtex/faststore/@faststore/api@3a31c2a

@faststore/cli

npm i https://pkg.pr.new/vtex/faststore/@faststore/cli@3a31c2a

@faststore/components

npm i https://pkg.pr.new/vtex/faststore/@faststore/components@3a31c2a

@faststore/core

npm i https://pkg.pr.new/vtex/faststore/@faststore/core@3a31c2a

@faststore/diagnostics

npm i https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@3a31c2a

@faststore/lighthouse

npm i https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@3a31c2a

@faststore/sdk

npm i https://pkg.pr.new/vtex/faststore/@faststore/sdk@3a31c2a

@faststore/ui

npm i https://pkg.pr.new/vtex/faststore/@faststore/ui@3a31c2a

commit: 3a31c2a

@eduardoformiga
eduardoformiga marked this pull request as ready for review September 29, 2026 23:34
@eduardoformiga
eduardoformiga requested a review from a team as a code owner September 29, 2026 23:34
@eduardoformiga
eduardoformiga requested review from lemagnetic and renatamottam and removed request for a team September 29, 2026 23:34
productClusters: Record<string, string>
clusterHighlights: ProductCluster[]
productClusters: ProductCluster[]
categories: string[]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Interface] 🔴 BLOCK

productClusters was changed from Record<string, string> (an ID→name map, as returned by the VTEX search client) to ProductCluster[] with no parsing/mapping code added anywhere in this diff. The new resolver productGroup.ts (isVariantOf.productClusters ?? []) just passes the raw value straight through, assuming it is already an array of {id, name} objects. If the actual VTEX Intelligent Search payload still comes back as an object map (which is what the prior type declared), GraphQL will fail trying to iterate a non-iterable object for the [StoreProductCluster!]! field, or silently serialize garbage.

Action: Confirm the real VTEX Search API response shape for productClusters. If it is still a map, add an explicit Object.entries(...) transformation into {id, name}[] in the client/resolver, and add a unit test that uses the real (map) fixture shape rather than one that already matches the target GraphQL type.

To dismiss: reply /dk-review dismiss [reason] under this comment

clusterHighlights: Record<string, any>
productClusters: Record<string, string>
clusterHighlights: ProductCluster[]
productClusters: ProductCluster[]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Interface] 🟡 RESTRICT

clusterHighlights was also retyped from Record<string, any> to ProductCluster[] in the same change, with no accompanying transformation logic and no consumer updated in this diff. This is the same unresolved shape mismatch as productClusters and will surface as a bug for any future/existing consumer of this field once type-checking is relied upon.

Action: Either revert this field's type until an actual consumer/transform is implemented, or verify and encode the real search-client response shape before merge.

To dismiss: reply /dk-review dismiss [reason] under this comment

@sonar-workflows

Copy link
Copy Markdown

@eduardoformiga eduardoformiga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. One upgrade note, not a change request.

productClusters is new on StoreProductGroup (isVariantOf). That does not collide with the usual store extension, which adds the field on StoreProduct:

extend type StoreProduct {
  productClusters: [IProductClusters!]
}

Existing product { productClusters { id name } } queries keep using the store resolver. clusterHighlights is not added to the schema, so extend type StoreProductGroup { clusterHighlights } stays valid.

The case that fails faststore generate is a store that already has extend type StoreProductGroup { productClusters: SomeOtherType }. Schema merge throws Field "productClusters" already defined with a different type. In the stores checked (farewayqa, marinbrasil, devmarinbrasil), productClusters is on StoreProduct, and StoreProductGroup only extends specificationGroups and clusterHighlights. This was a sample, not every store.

@eduardoformiga
eduardoformiga merged commit d82c21b into dev Sep 29, 2026
16 of 17 checks passed
@eduardoformiga
eduardoformiga deleted the codex/expose-product-clusters branch September 29, 2026 23:48
@eduardoformiga eduardoformiga mentioned this pull request Sep 30, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributing Pull request submitted by the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants