Skip to content

fix(catalog): normalize missing product entitlements - #2319

Merged
charlietlamb merged 1 commit into
devfrom
charlie/normalize-product-response-dev
Jul 20, 2026
Merged

fix(catalog): normalize missing product entitlements#2319
charlietlamb merged 1 commit into
devfrom
charlie/normalize-product-response-dev

Conversation

@charlietlamb

@charlietlamb charlietlamb commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Normalize missing product prices and entitlements at catalog response boundaries so incomplete historical products cannot crash preview/update.


Summary by cubic

Normalize missing product entitlements in catalog responses to prevent crashes when previewing or updating historical products. Undefined entitlements are now treated as empty arrays in the plan and product response mappers.

Written for commit aa5ba51. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR adds null-coalescing guards (?? []) on product.entitlements in the two catalog API response mappers (getPlanResponse and getProductResponse) to prevent runtime crashes when historical products are loaded without entitlements populated.

  • Bug fixesgetPlanResponse: product.entitlements ?? [] is passed to mapToProductItems, preventing a TypeError when iterating over undefined entitlements on historical products during catalog preview or update.
  • Bug fixesgetProductResponse: the identical guard is added in the sibling mapper, closing the same crash path for the product-level API response.

Confidence Score: 4/5

Safe to merge — both changes are a one-line null-coalesce guard with no side effects on valid data.

The two changed functions are the only catalog response boundary mappers, and the guard is correct. Several other mapToProductItems call sites (e.g. catalogMappingUtils.ts, invoiceMemoUtils.ts) pass product.entitlements without the same guard, so the same crash can still surface via adjacent flows if those paths receive a historical product with missing entitlements.

server/src/internal/catalog/actions/catalogMappings/catalogMappingUtils.ts and the attach-preview helpers (getUpgradeProductPreview.ts, getNewProductPreview.ts, getDowngradeProductPreview.ts) pass entitlements without a null-coalesce guard.

Important Files Changed

Filename Overview
server/src/internal/products/productUtils/productResponseUtils/getPlanResponse.ts Adds ?? [] fallback for product.entitlements before passing to mapToProductItems; safe and targeted fix.
server/src/internal/products/productUtils/productResponseUtils/getProductResponse.ts Identical ?? [] guard added for the product-level response mapper; consistent with the plan mapper fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Catalog Preview / Update Request] --> B[setupPreviewCatalogContext]
    B --> C{Historical version?}
    C -- yes --> D[ProductService.getFull with version]
    C -- no --> E[ProductService.listFull cached]
    D --> F[FullProduct - entitlements may be undefined]
    E --> G[FullProduct - entitlements present]
    F --> H[getPlanResponse / getProductResponse]
    G --> H
    H --> I{entitlements null-coalesce}
    I -- before fix: undefined --> J[TypeError: Cannot iterate undefined]
    I -- after fix: empty array --> K[mapToProductItems - safe iteration]
    K --> L[API response returned]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Catalog Preview / Update Request] --> B[setupPreviewCatalogContext]
    B --> C{Historical version?}
    C -- yes --> D[ProductService.getFull with version]
    C -- no --> E[ProductService.listFull cached]
    D --> F[FullProduct - entitlements may be undefined]
    E --> G[FullProduct - entitlements present]
    F --> H[getPlanResponse / getProductResponse]
    G --> H
    H --> I{entitlements null-coalesce}
    I -- before fix: undefined --> J[TypeError: Cannot iterate undefined]
    I -- after fix: empty array --> K[mapToProductItems - safe iteration]
    K --> L[API response returned]
Loading

Reviews (1): Last reviewed commit: "fix(catalog): normalize missing product ..." | Re-trigger Greptile

@capy-ai

capy-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Capy auto-review is paused for this organization because the usage-cycle auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews.

@charlietlamb
charlietlamb merged commit 8389614 into dev Jul 20, 2026
16 checks passed
@charlietlamb
charlietlamb deleted the charlie/normalize-product-response-dev branch July 20, 2026 20:13
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.

1 participant