fix(catalog): normalize missing product entitlements - #2319
Merged
Conversation
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Greptile Summary
This PR adds null-coalescing guards (
?? []) onproduct.entitlementsin the two catalog API response mappers (getPlanResponseandgetProductResponse) to prevent runtime crashes when historical products are loaded without entitlements populated.getPlanResponse:product.entitlements ?? []is passed tomapToProductItems, preventing aTypeErrorwhen iterating overundefinedentitlements on historical products during catalog preview or update.getProductResponse: 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
mapToProductItemscall sites (e.g.catalogMappingUtils.ts,invoiceMemoUtils.ts) passproduct.entitlementswithout 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
?? []fallback forproduct.entitlementsbefore passing tomapToProductItems; safe and targeted fix.?? []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]%%{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]Reviews (1): Last reviewed commit: "fix(catalog): normalize missing product ..." | Re-trigger Greptile